Water quality monitoring method and device, storage medium and electronic equipment
By adding periodic markers to water quality data and using water quality analysis models to process these data, the problem that traditional methods are difficult to capture the periodic characteristics of water quality data is solved, and the accuracy and stability of water quality prediction are significantly improved.
Patent Information
- Application Number
- CN202510564387.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-30
- Publication Date
- 2025-07-01
AI Technical Summary
Traditional water quality prediction methods are difficult to capture the spatial correlation between multiple monitoring sites and dependencies in long time series, and the conventional Transformer model is insufficiently sensitive to local periodic features, affecting the prediction accuracy.
By obtaining the historical water quality parameter set, adding periodic identifications are used to encode periodic laws in the water quality data, and processing the optimized parameter set using a pre-trained water quality analysis model to generate water quality prediction results at future time points.
The introduction of periodic marking significantly improves the model's sensitivity to local periodic characteristics and improves the overall water quality prediction effect.
Smart Images

Figure CN120233058A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of ecological environment, and in particular, to a water quality monitoring method, device, storage medium, and electronic device. Background Art
[0002] Traditional water quality prediction methods (e.g., ARIMA and LSTM) face significant technical bottlenecks when dealing with multi-site water quality monitoring data, manifested as difficulty in effectively capturing the spatial correlation between multiple monitoring sites and the dependency relationships in long time series, resulting in inaccurate and unstable prediction results when facing water quality data with complex spatio-temporal characteristics. At the same time, although the conventional Transformer model has strong sequence modeling capabilities, there are still several technical deficiencies in water quality time series analysis, manifested as significantly insufficient sensitivity to local periodic characteristics, such as limited ability to capture patterns like daily and weekly variations, thus affecting the prediction accuracy. Summary of the Invention
[0003] To overcome at least one deficiency in the prior art, the present application provides a water quality monitoring method, device, storage medium, and electronic device, specifically including:
[0004] In a first aspect, the present application provides a water quality monitoring method, the method including:
[0005] Obtaining a plurality of historical parameter sets arranged in chronological order, where each historical parameter set includes various water quality impact information;
[0006] Adding a period identifier to various water quality impact information in each historical parameter set to obtain a plurality of optimized parameter sets, where the period identifier represents the distribution law of the sampling time of the corresponding water quality impact information relative to the belonging cycle period;
[0007] Processing the plurality of optimized parameter sets through a pre-trained water quality analysis model to obtain a water quality prediction result at a future time point.
[0008] In a second aspect, the present application provides a water quality monitoring device, the device including:
[0009] A parameter acquisition module, configured to obtain a plurality of historical parameter sets arranged in chronological order, where each historical parameter set includes various water quality impact information;
[0010] A parameter preprocessing module, configured to add a period identifier to various water quality impact information in each historical parameter set to obtain a plurality of optimized parameter sets, where the period identifier represents the distribution law of the sampling time of the corresponding water quality impact information relative to the belonging cycle period;
[0011] The water quality prediction module processes the multiple optimization parameter sets through a pre-trained water quality analysis model to obtain water quality prediction results at future time points.
[0012] In a fourth aspect, the present application provides a storage medium, wherein the storage medium stores a computer program, and the computer program implements the water quality monitoring method when executed by a processor.
[0013] In a fifth aspect, the present application provides an electronic device, comprising a processor and a memory, wherein the memory stores a computer program, and the computer program implements the water quality monitoring method when executed by the processor.
[0014] Compared with the prior art, this application has the following beneficial effects:
[0015] In the water quality monitoring method, device, storage medium and electronic device provided by the present application, the electronic device obtains multiple historical parameter sets arranged in chronological order; wherein each historical parameter set includes multiple water quality impact information; a period identifier is added to the multiple water quality impact information in each historical parameter set to obtain multiple optimized parameter sets; wherein the period identifier characterizes the distribution law of the sampling time of the corresponding water quality impact information relative to the corresponding cycle period; the multiple optimized parameter sets are processed by a pre-trained water quality analysis model to obtain the water quality prediction results at future time points. In this way, since the period identifier has encoded the periodic laws in the water quality data into the optimized parameter set, the water quality analysis model can extract these features more efficiently and generate water quality prediction results at future time points based on this. Therefore, the introduction of the period identifier significantly improves the model's sensitivity to local periodic features, thereby improving the overall water quality prediction effect. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0017] Figure 1 A schematic diagram of a water quality monitoring method according to an embodiment of the present invention;
[0018] Figure 2 A schematic diagram of the structure of an encoder in a water quality analysis model provided in an embodiment of the present application;
[0019] Figure 3 A schematic diagram of implementation details of sparse causal self-attention provided in an embodiment of the present application;
[0020] Figure 4 Schematic diagram of the binarization mask matrix provided by the embodiment of the present application;
[0021] Figure 5 Schematic diagram of the optimized binarization mask matrix provided by the embodiment of the present application;
[0022] Figure 6 Schematic diagram of the structure of the water quality monitoring device provided by the embodiment of the present application;
[0023] Figure 7 Schematic diagram of the structure of the electronic device provided by the embodiment of the present application. Detailed implementation manners
[0024] To make the objectives, technical solutions and advantages of the embodiments of the present application (hereinafter simply referred to as "the present embodiments") clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are some but not all of the embodiments of the present application. Usually, the components of the embodiments of the present application described and illustrated in the accompanying drawings here can be arranged and designed in various different configurations.
[0025] Therefore, the following detailed description of the embodiments of the present application provided in the accompanying drawings is not intended to limit the scope of the present application claimed, but merely represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without making creative efforts shall fall within the protection scope of the present application.
[0026] It should be noted that: like reference numerals and letters denote like items in the following drawings. Therefore, once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings.
[0027] In the description of the present application, it should be noted that the terms "first", "second", "third", etc. are only used for distinguishing descriptions and cannot be construed as indicating or implying relative importance. In addition, the terms "include", "comprise" or any other variant thereof are intended to cover non-exclusive inclusion, such that a process, method, article or device including a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the phrase "including a..." does not exclude the existence of additional identical elements in the process, method, article or device including the said element.
[0028] Based on the above statement, as introduced in the background technology, traditional water quality prediction methods (such as ARIMA and LSTM) are difficult to capture spatial correlation and dependencies in long time series. Although the conventional Transformer model has strong sequence modeling capabilities, it is obviously not sensitive enough to local periodic characteristics.
[0029] Based on the discovery of the above technical problems, the following technical solutions are proposed through creative work to solve or improve the above problems. It should be noted that the defects existing in the solutions in the above prior art are the results obtained after practice and careful study. Therefore, the discovery process of the above problems and the solutions proposed in the embodiments of the present application for the above problems below should be regarded as contributions to the present application in the process of invention and creation, and should not be understood as technical contents known to those skilled in the art.
[0030] In view of this, this embodiment provides a water quality monitoring method. Figure 1 As shown, the method includes:
[0031] S1, obtain multiple historical parameter sets arranged in chronological order.
[0032] Each historical parameter set includes a variety of water quality impact information.
[0033] S2, adding periodic labels to various water quality impact information in each historical parameter set to obtain multiple optimized parameter sets.
[0034] Among them, the period mark represents the distribution law of the sampling time of the corresponding water quality impact information relative to the cycle period to which it belongs.
[0035] S3, processes multiple optimization parameter sets through a pre-trained water quality analysis model to obtain water quality prediction results at future time points.
[0036] In this way, since the periodicity mark has encoded the periodicity in the water quality data into the optimization parameter set, the water quality analysis model can extract these features more efficiently and generate water quality prediction results at future time points based on them. Therefore, the introduction of periodicity marks significantly improves the model's sensitivity to local periodicity features, thereby improving the overall water quality prediction effect.
[0037] In this embodiment, the electronic device implementing the water quality monitoring method may be, but is not limited to, a mobile terminal, a tablet computer, a laptop computer, a desktop computer, a server, etc. When the electronic device is a server, the server may be a single server or a server group. The server group may be centralized or distributed (for example, the server may be a distributed system). In some embodiments, the server may be local or remote relative to the user terminal. In some embodiments, the server may be implemented on a cloud platform; by way of example only, the cloud platform may include a private cloud, a public cloud, a hybrid cloud, a community cloud, a distributed cloud, an inter-cloud, a multi-cloud, etc., or any combination thereof. In some embodiments, the server may be implemented on an electronic device having one or more components.
[0038] To make the solution provided in this embodiment clearer, the following takes the server as the electronic device implementing the method to Figure 1 elaborate on each step of the method shown in detail. However, it should be understood that the operations in the flowchart may not be implemented in sequence, and steps without a logical context relationship may be reversed or implemented simultaneously. In addition, those skilled in the art can add one or more other operations to the flowchart or remove one or more operations from the flowchart under the guidance of the content of this application. Continuing to refer to Figure 1 , the method includes:
[0039] S1, obtaining a plurality of historical parameter sets arranged in chronological order.
[0040] Among them, each historical parameter set includes various water quality impact information. Exemplarily, the various water quality impact information includes monitoring data collected by water quality sensors, meteorological data, and action identifiers of water quality impact policies. Among them, the action identifier indicates that when sampling various water quality impact information, it is still affected by water quality impact policies. By organizing these data into a unified spatio-temporal tensor, input data is provided for subsequent water quality prediction tasks.
[0041] Specifically, the monitoring data collected by water quality sensors includes indicators such as the pH value, dissolved oxygen, and turbidity of a certain water body, and its sampling frequency is once per hour; the meteorological data includes parameters such as temperature, humidity, and precipitation, which are also collected at hourly intervals; the action identifier of the water quality impact policy records the implementation time point and specific content of the policy related to water quality management. For example, "Implement new water quality monitoring regulations on January 1, 2023". Therefore, these data sources respectively reflect the internal characteristics of water quality changes, external environmental impacts, and policy intervention effects, constituting multi-dimensional information indispensable for water quality prediction tasks.
[0042] In order to effectively integrate the above multi-source data, time alignment operations are required. Assuming that the selected time range is from January 1, 2023 to January 10, 2023, the timestamps of each data source need to be standardized to ensure that their time points can strictly correspond. On this basis, the information of different data sources is synchronized to the same time point through causal filling technology. For example, at 2023-01-01 00:00, the following data can be obtained:
[0043] Water quality data (pH = 7.5, dissolved oxygen = 8.0, turbidity = 2.0), meteorological data (temperature = 15°C, humidity = 80%, precipitation = 0 mm), and policy data (implementation of new water quality monitoring regulations).
[0044] Next, we need to integrate the aligned data into a unified space-time tensor. The specific method is to represent the data at each time point as a vector, the dimensions of which include water quality parameters, meteorological parameters, and policy effect identifiers. For example, for the data at 2023-01-01 00:00, its vector form can be expressed as:
[0045] [7.5,8.0,2.0,15,80,0,1]
[0046] The last element "1" is used to represent the implementation status of the policy (1 means it has been implemented, 0 means it has not been implemented). By performing the same processing on the data at each time point, a complete vector sequence can be generated. For example, for all time points from 2023-01-01 to 2023-01-10, the following vector sequence can be generated:
[0047] [7.5,8.0,2.0,15,80,0,1]
[0048] [7.4,7.9,2.1,14,82,0,1]
[0049] …….
[0050] Therefore, multiple historical parameter sets of vector sequences are not only convenient for subsequent water quality analysis models to process, but can also fully reflect the comprehensive relationship between water quality changes, meteorological impacts, and policy implementation.
[0051] Based on the explanation of step S1 in the above implementation, the following is Figure 1 Step S2 in the following is explained:
[0052] S2, adding periodic labels to various water quality impact information in each historical parameter set to obtain multiple optimized parameter sets.
[0053] Among them, the period mark represents the distribution law of the sampling time of the corresponding water quality impact information relative to the cycle period to which it belongs.
[0054] Research findings show that water quality data often contain obvious periodic characteristics, such as daily variations, weekly variations, and monthly variations. However, the traditional positional encoding method adopted by Transformer cannot fully adapt to these complex spatio-temporal heterogeneities, thus limiting the model's ability to learn periodic patterns. Fourier series can decompose periodic signals into a superposition of a series of sine and cosine functions, thereby providing a mathematically precise and intuitive way to describe periodic characteristics. Therefore, a periodic positional encoding method based on Fourier series is introduced in this embodiment.
[0055] In an alternative embodiment based on the above inventive concept, for various water quality impact information in each historical parameter set, the server obtains the sampling time of each water quality impact information; performs sine and cosine operations on the ratio between the sampling time of each water quality impact information and the corresponding cycle period to obtain the cycle identifier of each water quality impact information.
[0056] Specifically, the relationship among the cycle identifier, sampling time, and cycle period is as follows:
[0057] v1 = sin(2π * t / T)
[0058] v2 = cos(2π * t / T)
[0059] In the formula, [v1, v2] represents the cycle identifier, t represents the sampling time, and T represents the cycle period corresponding to the sampling time.
[0060] In this embodiment, the water quality analysis model can adopt a structure similar to that of the Transformer model or a derivative model based on Transformer. Exemplarily, the structure of the encoder of the water quality analysis model can refer to Figure 2 , and the encoder of the water quality analysis model includes a model architecture with 4 encoding layers, 8 heads per layer, and a hidden layer dimension of 512. The PPE (Periodic Positional Encoding) layer in the figure is used to add cycle identifiers to various water quality impact information in each historical parameter set.
[0061] Since water quality data usually contain significant periodic characteristics, such as daily variations, weekly variations, and monthly variations. To enable the model to learn these periodic patterns more effectively, the concept of cycle identifiers is introduced, and these vectors are generated by fusing Fourier series. Since the basic idea of Fourier series is to represent a periodic signal as a superposition of multiple sine and cosine functions. Therefore, in this scheme, the process of constructing cycle identifiers is essentially an explicit encoding of the periodic characteristics of the sampling time of water quality data.
[0062] Exemplarily, assume that the data being processed is a time series containing daily temperature records, and it is desired that the model can capture the daily periodic variations in temperature (e.g., daytime temperature is higher than nighttime temperature). To this end, a sine and cosine function with a cycle period of 24 hours can be defined to represent such periodic variations. For each time point t (in hours), the corresponding sine basis vector and cosine basis vector are respectively:
[0063] v1 = sin(2π / t / 24)
[0064] v2 = cos(2π*t / 24)
[0065] , in this way, the corresponding sine and cosine values can be calculated for each hour. For example, at midnight when t = 0, sin(2π0 / 24) = 0 and cos(2π0 / 24) = 1, so the period identifier is [0,1].
[0066] Similarly, for 6 am when t = 6, sin(2π6 / 24) = 1 and cos(2π6 / 24) = 0, so the period identifier is [1,0]. And so on, the period identifiers for other sampling times can be obtained.
[0067] To more comprehensively describe the periodic characteristics in water quality data, it can also be extended to periodic variations on other time scales. For example, when time is measured in days, and the cycle period is one week or one month, the corresponding sine and cosine functions can be defined respectively. When the cycle period is one week, the corresponding sine basis vector and cosine basis vector are respectively:
[0068] v1 = sin(2π*t / 168)
[0069] v2 = cos(2π*t / 168)
[0070] When the cycle period is one month, the corresponding sine basis vector and cosine basis vector are respectively:
[0071] v1 = sin(2π*t / 720)
[0072] v2 = cos(2π*t / 720)
[0073] Therefore, the period identifier of each water quality impact information is input into the model as an additional feature, thus providing the model with prior knowledge about time periodicity, enabling the model to effectively capture the daily, weekly, monthly and other periodic laws in water quality data.
[0074] Based on the above explanation of step S2 in the embodiment, next, continue to explain step S1 in Figure 1 :
[0075] S3. Process multiple sets of optimized parameters through a pre-trained water quality analysis model to obtain the water quality prediction results at future time points.
[0076] It should be understood that the above-mentioned future time points do not refer to a single time point only, but can be flexibly set as multiple consecutive or discrete time points according to actual needs. For example, when conducting long-term monitoring of water quality, it may be necessary to predict the changing trends of water quality parameters every hour within the next day, or the key water quality indicators every day within the next week.
[0077] Since the water quality analysis model adopts a structure similar to the Transformer model or a derivative model based on Transformer, the water quality analysis model provides a self-attention mechanism. It should be understood that the self-attention mechanism is a computational method for processing sequence data, and its core lies in generating a weighted representation by measuring the mutual relationships between different elements in the sequence. The core calculation steps of the self-attention mechanism involve constructing an attention score matrix, and the dimension of this matrix is the square of the sequence length. Therefore, when the set of optimized parameters contains a long sequence, generating and processing this large-scale matrix will significantly increase memory occupancy and computational time. In this regard, the present embodiment provides the following alternative implementation of step S3:
[0078] S3-1. Obtain the variances of multiple sets of optimized parameters according to the multiple sets of optimized parameters.
[0079] S3-2. If the variance is less than the variance threshold, split the multiple sets of optimized parameters into sequence segments; and perform self-attention operations on each sequence segment through the pre-trained water quality analysis model to obtain the water quality prediction results at future time points.
[0080] S3-3. If the variance is greater than or equal to the variance threshold, perform self-attention operations on the multiple sets of optimized parameters through the pre-trained water quality analysis model to obtain the water quality prediction results at future time points.
[0081] In the above implementation, by introducing the variance threshold judgment logic, the dynamic adjustment of the processing method of the set of optimized parameters is realized. Specifically, by calculating the variance of multiple sets of optimized parameters, the degree of change of the water quality impact information in these parameter sets can be quantitatively evaluated. When the variance is less than the set variance threshold, it indicates that the data in the set of optimized parameters is relatively stable, that is, the water quality impact information at each time point in the sequence changes less, and the local dependence is stronger while the global dependence is weaker. In this case, splitting the set of optimized parameters into several shorter sequence segments can not only effectively reduce the input length of a single self-attention operation, but also make full use of the advantages of the local attention mechanism to focus on capturing the dependencies within a short time window, thereby significantly reducing the consumption of computing resources.
[0082] On the contrary, when the variance is greater than or equal to the variance threshold, it indicates that there may be large fluctuations or mutations in the optimized parameter set, which usually means that the water quality impact information has strong non-linear characteristics or global dependencies in the time series. For example, the implementation of certain policies or extreme meteorological events may cause drastic changes in water quality parameters in a short period of time. At this time, if only local information is concerned, key change points and their context dependencies may be missed, thus affecting the prediction accuracy. Therefore, it becomes a necessary choice to directly perform self-attention operations on the complete optimized parameter set to ensure that the model can globally consider the information correlation of the entire sequence, capture these key change points and their impact on the overall water quality prediction results.
[0083] In this way, by combining the time series characteristics of water quality data with the computational characteristics of the self-attention mechanism, the balance between computational efficiency and prediction accuracy is achieved by dynamically adjusting the attention range.
[0084] On this basis, this embodiment also proposes sparse causal self-attention to reduce the computational complexity by restricting the attention range. Therefore, when performing self-attention operations, the server obtains the mean and standard deviation of the attention score matrix according to the attention score matrix of the sequence segment; adjusts the mean using the standard deviation to obtain the mask threshold; generates a binary mask matrix with the same dimension as the attention score matrix, where each element in the upper right part of the binary mask matrix is a mask; if the matrix element in the lower left part of the attention score matrix is less than or equal to the mask threshold, the corresponding position in the binary mask matrix is marked as a mask to obtain an optimized binary mask matrix; applies the optimized binary mask matrix to the attention score matrix to obtain an optimized attention score matrix; multiplies the optimized attention score matrix by the value matrix of the sequence segment to obtain a self-attention output matrix.
[0085] Among them, the relationship between the standard deviation, the mean, and the mask threshold is:
[0086] τ = μ + ασ
[0087] In the formula, τ represents the mask threshold, μ represents the mean, σ represents the standard deviation, and α represents the adjustment coefficient trained during the training of the water quality analysis model.
[0088] Regarding this, reference can be continued to Figure 2 , and the SCSA (Sparse Causal Self-Attention) layer in the figure sparsely processes the mask matrix. For the implementation details of the SCSA layer, the following will be more intuitively described in combination with Figure 3 For the input sequence, multiple sequence segments are divided by a sliding window of size k, each sequence segment corresponds to a window, and positional encoding is performed within each window. Based on the causal constraint relationship that is only forward visible within each window, a binary mask matrix is generated. AsFigure 4 As shown, assuming that the dimension of the data in each sequence segment is 10, after the sequence segment is successively mapped through a query matrix (Q matrix), a key-value matrix (K matrix), and a value matrix (V matrix), a query mapping matrix, a key-value mapping matrix, and a value mapping matrix of the sequence segment are obtained. After multiplying the query mapping matrix and the key-value mapping matrix and normalizing, an attention score matrix is obtained, and the dimension of this matrix is 10×10.
[0089] Since the binary mask matrix has the same dimension as the attention score matrix, the dimension of the binary mask matrix is also 10×10. According to the causal constraint relationship that is only forward visible within each window, that is, when the conditions i - j < k and j ≤ i are satisfied, a visible identifier (for example, 1) is marked at the corresponding element position in the binary mask matrix, while for the element positions that do not satisfy this condition, a mask (for example, 0) is marked. Therefore, the Figure 4 binary mask matrix shown can be obtained. Since Figure 4 the elements in the upper right corner of the binary mask matrix shown are all masks, this binary mask matrix is also called a triangular band matrix.
[0090] Then, the elements in the attention score matrix are statistically analyzed to obtain its mean and variance:
[0091] μ = mean(A_raw)
[0092] σ = std(A_raw)
[0093] In the formula, A_raw represents the attention score, and the mask threshold is obtained by substituting τ = μ + ασ. Then, the elements in the attention score matrix corresponding to the lower left corner of the Figure 4 binary mask matrix shown are compared with this mask threshold. When it is less than or equal to this mask threshold, the corresponding element position is marked as a mask (0).
[0094] Assume Figure 4 the binary mask matrix shown is optimized to obtain the optimized binary mask matrix as shown in Figure 5 When the optimized binary mask matrix acts on the attention score matrix, an optimized attention score matrix is obtained. The so-called action of the optimized binary mask matrix on the attention score matrix means multiplying the elements at the same positions of the two matrices.
[0095] Thus, based on the sliding window, considering that there may still be some attention weights that contribute less to the prediction results. For example, data at some adjacent time points may exhibit low correlation due to noise or data stationarity. The binarized mask matrix is further screened through a dynamic threshold to select the most representative attention weights. Moreover, the calculation of the dynamic threshold is based on the mean and standard deviation of the attention score matrix, which can dynamically adapt to different data distribution characteristics. More importantly, most elements in the mask matrix are marked as 0, and the optimized attention score matrix exhibits a sparsity property, enabling subsequent matrix multiplication operations to be performed only on non-zero elements, thus significantly reducing the actual computational amount.
[0096] The inference process of the water quality analysis model was described in the above embodiments. However, it should be understood that during the training process of the model, the design of the loss function fully considered the special requirements of the water quality prediction task and combined two aspects of losses through weighting. Specifically, its loss function jointly optimized the prediction error (Mean Absolute Error, MAE) and the performance index (F1-score) for water quality mutation event detection, thereby ensuring that the model can effectively capture abnormal changes in water quality data while providing high-precision prediction results.
[0097] Among them, the prediction error, as the core index to measure the prediction accuracy of the model, reflects the absolute deviation between the predicted value and the true value of water quality parameters at future time points. In the water quality prediction task, accurate numerical prediction is crucial for guiding water resource management decisions. Therefore, by minimizing the prediction error, the model can better fit the spatio-temporal patterns in historical data and improve the prediction ability for future water quality parameters.
[0098] The performance index for water quality mutation event detection is the key index to evaluate the sensitivity of the model to abnormal events. Since water quality data often contains mutation events caused by external factors (such as rainfall, sewage discharge policies, etc.), these events may have a significant impact on water body health. By introducing the performance index for water quality mutation event detection, the model can pay more attention to the identification ability of these mutation events during the training process, thereby improving the overall interpretability and practicality.
[0099] Therefore, the above two aspects of losses are incorporated into a unified loss function through a weighted combination, and the expression is:
[0100] L = α·MAE + β·FocalLoss(y_event)
[0101] In the formula, MAE represents the prediction error, FocalLoss represents the performance index for water quality mutation event detection, and α and β are weight coefficients used to balance the relative importance between the two.
[0102] Based on the same inventive concept as the water quality monitoring method provided in this embodiment, this embodiment also provides a water quality monitoring device, which includes at least one software function module that can be stored in a memory or fixed in an electronic device in the form of software. The processor in the electronic device is used to execute the executable module stored in the memory. For example, the software function module and computer program included in the device. Please refer to Figure 6 , from a functional perspective, the device may include:
[0103] The parameter acquisition module 11 is used to acquire a plurality of historical parameter sets arranged in chronological order, wherein each historical parameter set includes a plurality of water quality impact information;
[0104] A parameter preprocessing module 12 is used to add a period identifier to a plurality of water quality impact information in each historical parameter set to obtain a plurality of optimized parameter sets, wherein the period identifier represents the distribution law of the sampling time of the corresponding water quality impact information relative to the corresponding cycle period;
[0105] The water quality prediction module 13 processes multiple optimization parameter sets through a pre-trained water quality analysis model to obtain water quality prediction results at future time points.
[0106] In this embodiment, the parameter acquisition module 11 is used to implement Figure 1 In step S1, the parameter preprocessing module 12 is used to implement Figure 1 In step S2, the water quality prediction module 13 is used to implement Figure 1 Therefore, for the detailed description of the above modules, please refer to the specific implementation of the corresponding steps.
[0107] Optionally, before generating period identifiers for the various water quality impact information in each historical parameter set to obtain multiple optimized parameter sets, the parameter preprocessing module 12 is further used to:
[0108] For each type of water quality impact information in each historical parameter set, obtain the sampling time of each type of water quality impact information;
[0109] Perform sine and cosine operations on the ratio between the sampling time of each water quality impact information and the corresponding cycle period to obtain the cycle identifier of each water quality impact information
[0110] Optionally, the water quality analysis model provides a self-attention mechanism, and the water quality prediction module 13 is further specifically used for:
[0111] According to the multiple optimization parameter sets, variances of the multiple optimization parameter sets are obtained;
[0112] If the variance is less than the variance threshold, split multiple optimized parameter sets into sequence segments; and perform self-attention operations on each sequence segment through a pre-trained water quality analysis model to obtain the water quality prediction results at future time points;
[0113] If the variance is greater than or equal to the variance threshold, perform self-attention operations on multiple optimized parameter sets through a pre-trained water quality analysis model to obtain the water quality prediction results at future time points.
[0114] Optionally, when performing self-attention operations, the water quality prediction module 13 is further specifically configured to:
[0115] Obtain the mean and standard deviation of the attention score matrix according to the attention score matrix of the sequence segment;
[0116] Adjust the mean using the standard deviation to obtain the mask threshold;
[0117] Generate a binary mask matrix with the same dimension as the attention score matrix, where each element in the upper right part of the binary mask matrix is a mask;
[0118] If the matrix elements in the lower left part of the attention score matrix are less than or equal to the mask threshold, mark the corresponding positions in the binary mask matrix as masks to obtain an optimized binary mask matrix;
[0119] Apply the optimized binary mask matrix to the attention score matrix to obtain an optimized attention score matrix;
[0120] Multiply the optimized attention score matrix by the value matrix of the sequence segment to obtain a self-attention output matrix.
[0121] In addition, each functional module in various embodiments of the present application can be integrated together to form an independent part, or each module can exist alone, or two or more modules can be integrated to form an independent part.
[0122] It should also be understood that if the above implementation manner is implemented in the form of a software functional module 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 application, in essence, or the part that contributes to the prior art, or a part of this 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 for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in various embodiments of the present application.
[0123] Therefore, this embodiment also provides a storage medium, which is a computer-readable storage medium. The storage medium stores a computer program, and when the computer program is executed by a processor, the water quality prediction method provided in this embodiment is implemented. Among them, the storage medium can be various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk, or an optical disc.
[0124] An electronic device for implementing the water quality prediction method provided in this embodiment. As Figure 7 shown, the electronic device may include a processor 22 and a memory 21. Moreover, the memory 21 stores a computer program, and the processor implements the water quality prediction method provided in this embodiment by reading and executing the computer program corresponding to the above embodiments in the memory 21.
[0125] Continue to refer to Figure 7 , the electronic device further includes a communication unit 23. Each element of the memory 21, the processor 22, and the communication unit 23 is directly or indirectly electrically connected to each other through a system bus 24 to achieve data transmission or interaction.
[0126] Among them, the memory 21 can be an information recording device based on any electronic, magnetic, optical, or other physical principles, and is used to record execution instructions, data, etc. In some embodiments, the memory 21 can be, but is not limited to, a volatile memory, a non-volatile memory, a storage drive, etc.
[0127] In some embodiments, the volatile memory can be a random access memory (Random Access Memory, RAM); in some embodiments, the non-volatile memory can be a read-only memory (Read Only Memory, ROM), a programmable read-only memory (Programmable Read-Only Memory, PROM), an erasable programmable read-only memory (Erasable Programmable Read-Only Memory, EPROM), an electrically erasable programmable read-only memory (Electric Erasable Programmable Read-Only Memory, EEPROM), a flash memory, etc.; in some embodiments, the storage drive can be a disk drive, a solid-state drive, any type of storage disk (such as an optical disc, a DVD, etc.), or a similar storage medium, or a combination thereof, etc.
[0128] The communication unit 23 is used to transmit and receive data via a network. In some embodiments, the network may include a wired network, a wireless network, an optical fiber network, a telecommunication network, an intranet, the Internet, a local area network (LAN), a wide area network (WAN), a wireless local area network (WLAN), a metropolitan area network (MAN), a wide area network (WAN), a public switched telephone network (PSTN), a Bluetooth network, a ZigBee network, or a near field communication (NFC) network, etc., or any combination thereof. In some embodiments, the network may include one or more network access points. For example, the network may include a wired or wireless network access point, such as a base station and / or a network switching node, and one or more components of the service request processing system may be connected to the network via the access point to exchange data and / or information.
[0129] The processor 22 may be an integrated circuit chip with signal processing capabilities, and the processor may include one or more processing cores (e.g., a single-core processor or a multi-core processor). By way of example only, the above-mentioned processor may include a central processing unit (CPU), an application specific integrated circuit (ASIC), an application specific instruction-set processor (ASIP), a graphics processing unit (GPU), a physics processing unit (PPU), a digital signal processor (DSP), a field programmable gate array (FPGA), a programmable logic device (PLD), a controller, a microcontroller unit, a reduced instruction set computing (RISC), or a microprocessor, etc., or any combination thereof.
[0130] It can be understood that Figure 7The structure shown is only illustrative. The electronic device 100 may also have more or fewer components than Figure 7 shown, or have a different configuration from Figure 7 that shown. Figure 7 Each of the components shown may be implemented by hardware, software, or a combination thereof.
[0131] It should be understood that the devices and methods disclosed in the above embodiments may also be implemented in other ways. The device embodiments described above are merely illustrative. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architectures, functions, and operations of devices, methods, and computer program products according to multiple embodiments of the present application. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and the module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order from that marked in the accompanying drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and the combination of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or actions, or may be implemented by a combination of dedicated hardware and computer instructions.
[0132] As described above, these are only various embodiments of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art within the technical scope disclosed in the present application can easily think of changes or substitutions, which should all be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A water quality monitoring method, characterized in that: The method comprises: Acquire a plurality of historical parameter sets arranged in chronological order, wherein each of the historical parameter sets includes a plurality of water quality impact information; Adding a period mark to each of the multiple water quality impact information in the historical parameter set to obtain multiple optimization parameter sets, wherein the period mark represents the distribution law of the sampling time of the corresponding water quality impact information relative to the corresponding cycle period; The multiple optimization parameter sets are processed by a pre-trained water quality analysis model to obtain water quality prediction results at future time points.
2. The water quality monitoring method according to claim 1, characterized in that: Before generating a period mark for each of the multiple water quality impact information in the historical parameter set to obtain multiple optimized parameter sets, the method includes: For each of the multiple water quality impact information in the historical parameter set, obtaining the sampling time of each of the water quality impact information; The ratio between the sampling time of each type of water quality impact information and the corresponding cycle period is subjected to sine and cosine operations to obtain a cycle identifier for each type of water quality impact information.
3. The water quality monitoring method according to claim 2, characterized in that: The relationship between the cycle identifier, the sampling time, and the cycle period is: v1=sin(2π*t / T) v2=cos(2π*t / T) In the formula, [v1, v2] represents the cycle identifier, t represents the sampling time, and T represents the cycle period corresponding to the sampling time.
4. The water quality monitoring method according to any one of claims 1 to 3, characterized in that: Each of the multiple water quality impact information in the historical parameter set includes an effect identifier of a water quality impact policy, and the effect identifier indicates that when the multiple water quality impact information is sampled, it is still affected by the water quality impact policy.
5. The water quality monitoring method according to claim 1, characterized in that: The water quality analysis model is provided with a self-attention mechanism, and the plurality of optimization parameter sets are processed by the pre-trained water quality analysis model to obtain water quality prediction results at future time points, including: Obtaining variances of the multiple optimization parameter sets according to the multiple optimization parameter sets; If the variance is less than the variance threshold, splitting the multiple optimization parameter sets into sequence segments; and performing self-attention operation on each of the sequence segments through a pre-trained water quality analysis model to obtain a water quality prediction result at a future time point; If the variance is greater than or equal to the variance threshold, a self-attention operation is performed on the multiple optimization parameter sets through a pre-trained water quality analysis model to obtain a water quality prediction result at a future time point.
6. The water quality monitoring method according to claim 5, characterized in that: When performing a self-attention operation, the method includes: According to the attention score matrix of the sequence fragments, obtaining the mean and standard deviation of the attention score matrix; Using the standard deviation to adjust the mean value, a mask threshold is obtained; Generate a binary mask matrix of the same dimension as the attention score matrix, wherein each element in the upper right corner of the binary mask matrix is a mask; If the matrix element in the lower left corner of the attention score matrix is less than or equal to the mask threshold, the corresponding position in the binary mask matrix is marked as a mask to obtain an optimized binary mask matrix; Applying the optimized binary mask matrix to the attention score matrix to obtain an optimized attention score matrix; The optimized attention score matrix is multiplied by the value matrix of the sequence fragments to obtain a self-attention output matrix.
7. The water quality monitoring method according to claim 6, characterized in that: The relationship between the standard deviation, the mean and the mask threshold is: τ=μ+ασ In the formula, τ represents the mask threshold, μ represents the mean, σ represents the standard deviation, and α represents the adjustment coefficient trained during the training of the water quality analysis model.
8. A water quality monitoring device, characterized in that: The device comprises: A parameter acquisition module, used to acquire a plurality of historical parameter sets arranged in chronological order, wherein each of the historical parameter sets includes a plurality of water quality impact information; A parameter preprocessing module, used for adding a period mark to each of the multiple water quality impact information in the historical parameter set to obtain multiple optimization parameter sets, wherein the period mark represents the distribution law of the sampling time of the corresponding water quality impact information relative to the corresponding cycle period; The water quality prediction module processes the multiple optimization parameter sets through a pre-trained water quality analysis model to obtain water quality prediction results at future time points.
9. A storage medium, characterized in that: The storage medium stores a computer program, and the computer program, when executed by a processor, implements the water quality monitoring method according to any one of claims 1 to 7.
10. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory stores a computer program, and the computer program, when executed by the processor, implements the water quality monitoring method according to any one of claims 1 to 7.
Citation Information
Cited By
Remote management method and system for multi-terminal water quality analyzer cluster
CN121165675A