A tap water detection method, system and storage medium
By using pre-trained standard water quality detection models in tap water detection, combined with data pretreatment and particle swarm algorithm, the problem of insufficient real-time and accuracy of detection in the existing technology is solved, real-time detection of tap water and timely abnormal water sources are realized Early warning and water supply safety is ensured.
Patent Information
- Application Number
- CN202411119703.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-11-05
- Estimated Expiration
- 2044-08-15
AI Technical Summary
The existing tap water detection methods have poor real-time performance and low accuracy of abnormal detection results, making it difficult to timely warning and deal with abnormal water sources, especially in case of sudden pollution incidents, which cannot respond quickly.
By obtaining the current turbidity, pH, water temperature and dissolved oxygen concentration data, input it into the pre-trained standard water quality detection model, generate alarm instructions and close abnormal water sources. The model training process includes data preprocessing, PCA dimensionality reduction and particle swarm algorithm optimization , build an initial water quality detection model to improve detection accuracy.
Real-time detection of tap water and timely early warning and treatment of abnormal water sources are achieved, the accuracy of detection results is improved, and the safety of water supply and the sustainable use of water resources are ensured.
Smart Images

Figure CN118671291B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of water quality testing, and more particularly to a method, system, and storage medium for testing tap water. Background Technology
[0002] With the acceleration of urbanization and the improvement of people's living standards, the quality and stability of tap water supply are becoming increasingly important to public health and daily life. The real-time nature and accuracy of tap water testing are directly related to water quality safety, especially in the face of sudden pollution incidents. Timely detection and early warning of abnormal water sources are crucial measures to ensure water supply security. Furthermore, with increasing environmental awareness, water resource management not only needs to focus on water quality but also requires effective monitoring of water quantity and analysis of historical data to ensure the sustainable use of water resources.
[0003] Existing technologies have proposed a variety of tap water testing methods, including methods based on physicochemical parameters, such as the measurement of indicators like pH, turbidity, and dissolved oxygen. These methods mainly rely on on-site sampling and laboratory analysis.
[0004] In existing technologies, laboratory analysis often takes a long time, and the analysis process is easily affected by various interference factors, resulting in poor real-time detection, low accuracy of abnormal detection results, and difficulty in timely warning and handling of abnormal water sources. Summary of the Invention
[0005] This invention provides a method, system, and storage medium for tap water detection, enabling real-time detection of tap water, improving the accuracy of abnormal detection results, and providing timely warnings and handling of abnormal water sources.
[0006] In a first aspect, to solve the above-mentioned technical problems, the present invention provides a tap water testing method, comprising:
[0007] The system acquires current turbidity, pH, water temperature, and dissolved oxygen concentration data from the acquisition device and inputs them into a pre-trained standard water quality testing model to obtain a water quality test score.
[0008] When the water quality test score is determined to be less than a preset score threshold, an alarm command is generated and sent to the control terminal so that the control terminal can shut down the corresponding abnormal water source according to the alarm command.
[0009] The training process of the standard water quality testing model includes:
[0010] Acquire historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data;
[0011] Data preprocessing and PCA dimensionality reduction are performed on the historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data to obtain dimensionality-reduced data.
[0012] Using the dimensionality-reduced data and preset standard water quality data as input data, an initial water quality detection model is constructed based on the particle swarm optimization algorithm. The initial water quality detection model is then trained according to the membership matrix and the probability partitioning matrix to obtain the standard water quality detection model.
[0013] As an optional implementation, the step of performing data preprocessing and PCA dimensionality reduction on the historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data to obtain dimensionality-reduced data includes:
[0014] The historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data are standardized to obtain standardized data.
[0015] Based on the standardized data, the covariance matrix is calculated to obtain the correlation covariance matrix;
[0016] Based on the correlation covariance matrix, eigenvalue decomposition is performed to obtain eigenvalues and eigenvectors;
[0017] Based on the eigenvalues and the eigenvectors, a preset number of eigenvectors are selected in descending order of eigenvalues to obtain an eigenvector matrix.
[0018] Based on the standardized data and the feature vector matrix, the standardized data is projected onto the feature vector matrix to obtain dimensionality-reduced data.
[0019] As an optional implementation, the initial water quality detection model is constructed based on the dimensionality-reduced data and preset standard water quality data as input data, using particle swarm optimization. The initial water quality detection model is then trained according to the membership matrix and probability partitioning matrix to obtain the standard water quality detection model, including:
[0020] Initialize the cluster centers and number of clusters of the initial water quality detection model;
[0021] The particle swarm is initialized based on the cluster centers and the number of clusters, and full gradient inertial particle swarm optimization is performed to obtain the optimal initial cluster centers and the optimal initial number of clusters.
[0022] Based on the optimal initial cluster centers and the optimal initial number of clusters, initialize the parameters, membership matrix, and probability partitioning matrix of the initial water quality detection model;
[0023] Based on the current membership matrix and the probability partitioning matrix, the cluster centers are updated and trained;
[0024] When the number of training iterations is greater than or equal to the preset maximum number of training iterations, the training is considered complete, and a standard water quality testing model is obtained.
[0025] As an optional implementation, the step of initializing the particle swarm based on the cluster centers and the number of clusters, and performing full gradient inertial particle swarm optimization to obtain the optimal initial cluster centers and the optimal initial number of clusters includes:
[0026] The particle swarm is initialized based on the cluster centers and the number of clusters to obtain the initial particle swarm.
[0027] Based on the initial particle swarm, the particle inertia weight is calculated to obtain the inertia weight value of each particle.
[0028] Based on the initial particle swarm, particle fitness is calculated to obtain the fitness of each particle;
[0029] Based on the fitness and inertia weight value of each particle, the particle velocity and particle position are iterated using full gradient descent. When the number of iterations is greater than or equal to the preset maximum number of iterations, the iteration is determined to be complete, and the optimal initial cluster center and the optimal initial number of clusters are obtained.
[0030] Wherein, the particle position represents the cluster center and the number of clusters in the initial water quality detection model, and the particle velocity represents the update step size of the cluster center and the number of clusters.
[0031] As an optional implementation, the step of updating and training cluster centers based on the current membership matrix and the probability partitioning matrix includes:
[0032] Obtain the membership matrix and the probability partitioning matrix;
[0033] Based on the membership matrix and the probability partitioning matrix, distance calculation is performed to obtain the distance from each data point to all cluster centers;
[0034] For each cluster center, the contribution value is calculated based on the membership matrix to obtain the positional contribution value of each data point to each cluster center;
[0035] Based on the location contribution value, the weighted sum of the location contribution values of all data points is obtained to get the second cluster center;
[0036] Based on the second cluster center, the membership degree of all data points is recalculated to obtain the second membership degree matrix and the second probability partitioning matrix.
[0037] Replace the cluster center, the membership matrix, and the probability partitioning matrix with the second cluster center, the second membership matrix, and the second probability partitioning matrix, respectively.
[0038] As an optional implementation, the step of recalculating the membership degrees of all data points based on the second cluster centers to obtain a second membership degree matrix and a second probability partitioning matrix includes:
[0039] The membership degree is updated using the following formula.
[0040] ;
[0041] in, For the first The data point belongs to the first Membership degree of a class For the first The data point belongs to the first Membership degree of a class For the first The data point belongs to the first Class probability partitioning value, For the first The data point belongs to the first Class probability partitioning value, The number of clusters;
[0042] The probability partitioning matrix is updated using the following formula.
[0043] ;
[0044] in, For the first The data point belongs to the first Class probability partitioning value, For data points and the first Euclidean distance between cluster centers For the first Class scale parameter, It is a probability-weighted index.
[0045] As an optional implementation, the step of generating an alarm command when the water quality test score is determined to be less than a preset score threshold, and sending the alarm command to the control terminal so that the control terminal shuts down the corresponding abnormal water source according to the alarm command, further includes:
[0046] Obtain the water quality test score, current time data, and test location data obtained from the standard water quality test model;
[0047] The water quality test score is compared with a preset score threshold to determine whether the water quality is below the preset score threshold.
[0048] When the water quality test score is determined to be less than the preset score threshold, an alarm command is generated and sent to the control terminal.
[0049] Based on the information in the alarm command, the control terminal determines the abnormal water source that needs to be shut down;
[0050] The control unit performs a shutdown operation to stop the supply of the abnormal water source;
[0051] The alarm command includes the identification information of the abnormal water source, the current water quality test score, the abnormal time data, and the abnormal location data.
[0052] As an optional implementation, after sending the alarm command to the control terminal so that the control terminal shuts down the corresponding abnormal water source according to the alarm command, the method further includes:
[0053] Send the alarm command to the user terminal;
[0054] The user terminal receives alarm commands, parses and obtains the identification information of abnormal water sources, current water quality test scores, abnormal time data and abnormal location data;
[0055] Based on the identification information of the abnormal water source, the current water quality test score, the abnormal time data, and the abnormal location data, the user terminal notifies the user that the current water source is abnormal, marks the abnormal location, and issues an abnormal alarm.
[0056] Secondly, the present invention provides a tap water detection system, comprising:
[0057] The detection terminal is used to acquire turbidity data, pH data, water temperature data, dissolved oxygen concentration data, detection location data, and detection time data, and then send the detection data to the server.
[0058] The server is used to process the detection data. The server calculates the water quality detection score based on the standard water quality detection model. When the water quality detection score is determined to be less than a preset score threshold, an alarm command is generated and sent to the control terminal so that the control terminal can shut down the corresponding abnormal water source according to the alarm command.
[0059] The control terminal is used to receive instructions from the server and control the opening and closing of the water source;
[0060] The user terminal is used to receive instructions from the server, obtain detection data from the detection terminal, display the detection status, and when the alarm instruction is received, based on the detection data from the detection terminal, prompt the user that there is an anomaly in the current water source, mark the location of the anomaly, and issue an anomaly alarm.
[0061] Thirdly, the present invention also provides a computer-readable storage medium comprising a stored computer program, wherein, when the computer program is executed, it controls the device containing the computer-readable storage medium to perform any of the above-described tap water detection methods.
[0062] Compared with the prior art, the present invention has the following beneficial effects:
[0063] This invention provides a method for tap water testing, comprising: acquiring current turbidity data, current pH data, current water temperature data, and current dissolved oxygen concentration data collected by a data acquisition device, and inputting them into a pre-trained standard water quality testing model to obtain a water quality testing score; when the water quality testing score is determined to be less than a preset score threshold, generating an alarm command and sending the alarm command to a control terminal, so that the control terminal shuts down the corresponding abnormal water source according to the alarm command; wherein, the training process of the standard water quality testing model includes: acquiring historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data; performing data preprocessing and PCA dimensionality reduction on the historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data to obtain dimensionality-reduced data; based on the dimensionality-reduced data and the preset standard water quality data as input data, constructing an initial water quality testing model based on a particle swarm optimization algorithm, and training the initial water quality testing model according to a membership matrix and a probability partitioning matrix to obtain a standard water quality testing model. The method described above uses a standard water quality detection model trained with historical multidimensional water quality data to detect current water quality data in real time. This eliminates interference from various factors, enables real-time detection of tap water, improves the accuracy of abnormal detection results, and allows for timely warning and handling of abnormal water sources. Attached Figure Description
[0064] Figure 1 This is a schematic diagram of a tap water testing method provided in an embodiment of the present invention;
[0065] Figure 2 This is a training diagram of the standard water quality testing model provided in an embodiment of the present invention;
[0066] Figure 3 This is a flowchart illustrating the PSO-PFCM algorithm provided in an embodiment of the present invention;
[0067] Figure 4This is a schematic diagram of a tap water detection system provided in an embodiment of the present invention. Detailed Implementation
[0068] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0069] With the acceleration of urbanization and the improvement of people's living standards, the quality and stability of tap water supply are becoming increasingly important to public health and daily life. The real-time nature and accuracy of tap water testing are directly related to water quality safety, especially in the face of sudden pollution incidents. Timely detection and early warning of abnormal water sources are crucial measures to ensure water supply security. Furthermore, with increasing environmental awareness, water resource management not only needs to focus on water quality but also requires effective monitoring of water quantity and analysis of historical data to ensure the sustainable use of water resources.
[0070] Existing technologies have proposed a variety of tap water testing methods, including methods based on physicochemical parameters, such as the measurement of indicators like pH, turbidity, and dissolved oxygen. These methods mainly rely on on-site sampling and laboratory analysis.
[0071] In existing technologies, laboratory analysis often takes a long time, and the analysis process is easily affected by various interference factors, resulting in poor real-time detection, low accuracy of abnormal detection results, and difficulty in timely warning and handling of abnormal water sources.
[0072] To address the aforementioned issues, the following specific embodiments will provide a detailed description and explanation of a tap water testing method provided in this application.
[0073] Reference Figure 1 The first embodiment of the present invention provides a method for testing tap water, comprising the following steps:
[0074] S1: Acquire the current turbidity data, current pH data, current water temperature data, and current dissolved oxygen concentration data collected by the acquisition device, and input them into the pre-trained standard water quality detection model to obtain the water quality detection score.
[0075] S2, when the water quality test score is determined to be less than the preset score threshold, an alarm command is generated and sent to the control terminal so that the control terminal can shut down the corresponding abnormal water source according to the alarm command.
[0076] In step S1, the current turbidity data, current pH data, current water temperature data, and current dissolved oxygen concentration data collected by the acquisition device are obtained and input into the pre-trained standard water quality detection model to obtain the water quality detection score.
[0077] It's important to note that turbidity is caused by suspended particulate matter in the water, such as silt, organic matter, and microorganisms. These particles scatter and absorb light, thus affecting water transparency. pH value is an indicator of the acidity or alkalinity of water, determined by the concentration of hydrogen ions. Specifically, the pH value of natural water bodies is typically between 6.5 and 8.5. Water temperature is the result of the combined effects of ambient temperature, solar radiation, and water flow. Water temperature affects the metabolic activities and distribution of aquatic organisms, as well as the rate of chemical reactions in the water. Monitoring water temperature helps understand the ecological status and physicochemical properties of water bodies. Dissolved oxygen concentration is determined by factors such as oxygen exchange between the water body and the atmosphere, and photosynthesis by aquatic plants. Dissolved oxygen is essential for the survival of aquatic organisms, and its concentration directly affects the ecological health of the water body. These characteristics are acquired in real time by data collection equipment and input into a pre-trained standard water quality testing model. The model outputs a water quality test score based on this data. This score is a comprehensive indicator used to quickly assess the overall water quality status, helping decision-makers determine whether the water quality meets standards and whether further measures are needed. This method enables real-time monitoring and effective management of water quality, ensuring the safe and sustainable use of water resources.
[0078] like Figure 2 As shown, step S1 involves acquiring the current turbidity data, current pH data, current water temperature data, and current dissolved oxygen concentration data collected by the acquisition device, and inputting them into a pre-trained standard water quality testing model to obtain a water quality testing score, including:
[0079] S11, acquire historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data;
[0080] S12, perform data preprocessing and PCA dimensionality reduction operation on the historical turbidity data, historical pH data, historical water temperature data and historical dissolved oxygen concentration data to obtain dimensionality-reduced data;
[0081] S13, based on the dimensionality reduction data and the preset standard water quality data as input data, an initial water quality detection model is constructed based on the particle swarm optimization algorithm. The initial water quality detection model is trained according to the membership matrix and the probability partitioning matrix to obtain the standard water quality detection model.
[0082] The preset standard water quality data refers to a set of predefined reference data used to assess and compare water quality conditions. This data typically includes a series of water quality parameters, such as pH, dissolved oxygen concentration, water temperature, and turbidity, as well as the ideal or permissible ranges for these parameters. In specific applications, the standard water quality data are: pH between 6.5 and 8.5, dissolved oxygen concentration between 5.0 and 10.0 mg / L, water temperature between 0 and 30°C, and turbidity between 0 and 5 NTU. The preset standard water quality data provides a reference benchmark for the model, helping it learn how to identify and assess water quality conditions, ultimately resulting in an accurate and reliable water quality detection model.
[0083] In step S11, historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data are acquired.
[0084] It should be noted that this historical data comes from monitoring data over the past five years. Using historical data to train the standard water quality testing model aims to allow the model to learn the complex relationships and changing patterns among water quality parameters. During training, the model attempts to find the optimal mapping relationship between input data and output. In this embodiment, this means finding the mapping relationship between turbidity, pH value, water temperature, dissolved oxygen concentration, and water quality test scores. The trained standard water quality testing model can be used for real-time water quality prediction and assessment, helping to quickly determine the current water quality status.
[0085] In step S12, the historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data are preprocessed and subjected to PCA dimensionality reduction to obtain dimensionality-reduced data, including:
[0086] The historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data are standardized to obtain standardized data.
[0087] Based on the standardized data, the covariance matrix is calculated to obtain the correlation covariance matrix;
[0088] Based on the correlation covariance matrix, eigenvalue decomposition is performed to obtain eigenvalues and eigenvectors;
[0089] Based on the eigenvalues and the eigenvectors, a preset number of eigenvectors are selected in descending order of eigenvalues to obtain an eigenvector matrix.
[0090] Based on the standardized data and the feature vector matrix, the standardized data is projected onto the feature vector matrix to obtain dimensionality-reduced data.
[0091] In this embodiment of the invention, the calculation formula for standardization is:
[0092] ;
[0093] in, Represents the original data points; This represents the mean of the dataset; The standard deviation of the dataset; This represents the standardized data points.
[0094] It should be noted that the standardization process involves calculating the mean and standard deviation for each parameter. In this embodiment, the parameters for standardization are turbidity, pH value, water temperature, and dissolved oxygen concentration. Then, each data point is standardized. The purpose of standardization is to convert data of different dimensions and ranges to the same dimension, making the data comparable.
[0095] In this embodiment of the invention, the formula for calculating the covariance matrix is as follows:
[0096] ;
[0097] in, A standardized matrix representing the data; Represents the transpose of a normalized matrix; The degrees of freedom representing the sample covariance; Let represent the covariance matrix.
[0098] It should be noted that the covariance matrix is a square matrix calculated using standardized data, reflecting the correlation between various parameters. Eigenvalue decomposition is the process of decomposing the covariance matrix into eigenvalues and eigenvectors. Eigenvalues represent the magnitude of the variance of each principal component, and eigenvectors represent the direction of the principal components. The purpose of selecting eigenvectors is to retain the most important principal components. A preset number of eigenvectors are selected in descending order of eigenvalues, typically choosing those that can explain most of the variation. In this embodiment, the preset number of eigenvectors is 4. Depending on the application scenario and user needs, the preset number of eigenvectors can also be set to 5, 10, etc., and this invention does not limit this. Data projection uses the selected eigenvector matrix to perform a linear transformation on the standardized data, obtaining a new dataset, whose dimensionality is usually much smaller than the original data. Through this series of data preprocessing and PCA dimensionality reduction operations, the dimensionality of the data can be effectively reduced while retaining the most important information. The dimensionality-reduced data is easier to process and analyze, helping to improve the efficiency and accuracy of subsequent model training.
[0099] like Figure 3As shown, in step S13, the initial water quality detection model is constructed based on the dimensionality reduction data and the preset standard water quality data as input data, using the particle swarm optimization algorithm. The initial water quality detection model is then trained according to the membership matrix and the probability partitioning matrix to obtain the standard water quality detection model, including:
[0100] S131, Initialize the cluster centers and number of clusters of the initial water quality detection model;
[0101] S132, initialize the particle swarm based on the cluster centers and the number of clusters, perform full gradient inertial particle swarm optimization, and obtain the optimal initial cluster centers and the optimal initial number of clusters.
[0102] S133, Initialize the parameters, membership matrix, and probability partitioning matrix of the initial water quality detection model based on the optimal initial cluster centers and the optimal initial number of clusters;
[0103] S134, based on the current membership matrix and the probability partitioning matrix, update the cluster centers and train;
[0104] S135, when the number of training iterations is greater than or equal to the preset maximum number of training iterations, the training is considered complete, and a standard water quality detection model is obtained.
[0105] It should be noted that the cluster centers and the number of clusters are key parameters of the initial water quality detection model. The cluster centers define the aggregation points of the data, while the number of clusters determines the number of clusters. The initial cluster centers and the initial number of clusters are obtained through random initialization or based on prior knowledge, and are used to define the relationship between the model's input and output. The cluster centers are continuously adjusted during model training to determine the centers of normal water quality data, thereby eliminating various interference factors, achieving real-time detection of tap water, improving the accuracy of abnormal detection results, and enabling timely early warning and handling of abnormal water sources.
[0106] In step S132, the particle swarm optimization is initialized based on the cluster centers and the number of clusters, and full gradient inertial particle swarm optimization is performed to obtain the optimal initial cluster centers and the optimal initial number of clusters, including:
[0107] The particle swarm is initialized based on the cluster centers and the number of clusters to obtain the initial particle swarm.
[0108] Based on the initial particle swarm, the particle inertia weight is calculated to obtain the inertia weight value of each particle.
[0109] Based on the initial particle swarm, particle fitness is calculated to obtain the fitness of each particle;
[0110] Based on the fitness and inertia weight value of each particle, the particle velocity and particle position are iterated using full gradient descent. When the number of iterations is greater than or equal to the preset maximum number of iterations, the iteration is determined to be complete, and the optimal initial cluster center and the optimal initial number of clusters are obtained.
[0111] Wherein, the particle position represents the cluster center and the number of clusters in the initial water quality detection model, and the particle velocity represents the update step size of the cluster center and the number of clusters.
[0112] In this embodiment of the invention, the formula for calculating the inertia weight is as follows:
[0113] ;
[0114] in, It is a new inertial weight; It is the detection function value of the current iteration.
[0115] In this embodiment of the invention, the detection function is as follows:
[0116] ;
[0117] in, Represents the optimal solution for an individual; Indicates the globally optimal solution; Indicates the first The particle in the first The position at the next iteration; and This represents the Euclidean distance between the two. Indicates the first The detection function value of the next iteration.
[0118] In this embodiment of the invention, the update formulas for the velocity and position of the particles are as follows:
[0119] ;
[0120] ;
[0121] in, Indicates inertia weight; Indicates the number of iterations; Indicates the first The current velocity of a particle in the k-th iteration; Indicates the first The current velocity of a particle in the (k+1)th iteration; Indicates the first The current position of a particle in the k-th iteration; Indicates the first The current position of each particle in the (k+1)th iteration; A value of 2 indicates a self-learning factor; A value of 2 indicates a social learning factor; The value range is [0, 1], representing a random factor; The value range is [0, 1], representing a random factor; Represents the optimal solution for an individual; This represents the global optimal solution, embodying the idea of the full gradient descent method.
[0122] It is worth noting that the preset maximum number of iterations is a key parameter, determining the algorithm's convergence speed and the quality of the final solution. Setting it too small may cause the algorithm to converge prematurely, failing to find the globally optimal solution; setting it too large, while potentially finding a better solution, will increase computational cost and time consumption. In this embodiment, the maximum number of iterations is set to 100. Depending on the application scenario and user needs, the maximum number of iterations can also be set to 50, 200, etc., and this invention does not limit this setting.
[0123] In step S134, cluster centers are updated and trained based on the current membership matrix and the probability partitioning matrix, including:
[0124] Obtain the membership matrix and the probability partitioning matrix;
[0125] Based on the membership matrix and the probability partitioning matrix, distance calculation is performed to obtain the distance from each data point to all cluster centers;
[0126] For each cluster center, the contribution value is calculated based on the membership matrix to obtain the positional contribution value of each data point to each cluster center;
[0127] Based on the location contribution value, the weighted sum of the location contribution values of all data points is obtained to get the second cluster center;
[0128] Based on the second cluster center, the membership degree of all data points is recalculated to obtain the second membership degree matrix and the second probability partitioning matrix.
[0129] Replace the cluster center, the membership matrix, and the probability partitioning matrix with the second cluster center, the second membership matrix, and the second probability partitioning matrix, respectively.
[0130] In this cluster analysis, data points are the basic units, representing individuals that need to be classified or grouped. In this embodiment, the pH value, dissolved oxygen, turbidity, and water temperature of each detection point are reduced to a single data point using PCA. By clustering these data points, outliers or anomalies in the data are identified, thereby determining whether the water quality is abnormal.
[0131] It's worth noting that the membership matrix is a two-dimensional matrix, where each row corresponds to a data point and each column corresponds to a cluster center. Each element in the matrix represents the membership degree or probability of a data point belonging to a particular cluster center. Membership values are typically between 0 and 1, indicating the degree to which a data point belongs to that cluster center. The membership matrix is usually generated in the initial stage of the clustering algorithm using some initialization method, or calculated during iteration using update rules. The initialization method can be random assignment or based on some prior knowledge of the data points. The membership matrix is used in the clustering process to determine the relationship between data points and cluster centers. Using the membership matrix, the contribution value of each data point to each cluster center can be calculated, thereby updating the position of the cluster centers. For example, the probability partitioning matrix is similar to the membership matrix, also a two-dimensional matrix, but it is typically used to represent the uncertainty or probability of a data point belonging to a particular cluster center. The elements in the probability partitioning matrix represent the probability or confidence of a data point belonging to a particular cluster center. The probability partitioning matrix is derived from the membership matrix using some probability model or uncertainty measurement method. It reflects the probability that a data point belongs to any of the cluster centers given a membership matrix. The probability partitioning matrix is used in the clustering process to enhance the robustness and reliability of the clustering results. By considering the probability of a data point belonging to any of the cluster centers, the clustering results can be evaluated and optimized more comprehensively.
[0132] In this embodiment, the membership degree is calculated and updated using the following formula:
[0133] ;
[0134] in, For the first The data point belongs to the first Membership degree of a class For the first The data point belongs to the first Membership degree of a class For the first The data point belongs to the first Class probability partitioning value, For the first The data point belongs to the first Class probability partitioning value, The number of clusters;
[0135] In this embodiment, the probability partitioning matrix is updated using the following formula:
[0136] ;
[0137] in, For the first The data point belongs to the first Class probability partitioning value, For data points and the first Euclidean distance between cluster centers For the first Class scale parameter, It is a probability-weighted index.
[0138] In step S135, when the number of training iterations is greater than or equal to the preset maximum number of training iterations, the training is considered complete, and a standard water quality detection model is obtained.
[0139] It is worth noting that the preset maximum number of training iterations is a key parameter, determining when the training process of the probabilistic fuzzy C-clustering terminates. In this embodiment, the preset maximum number of training iterations is set to 200, a result verified through experiments, ensuring that a standard water quality detection model with acceptable performance is obtained within a reasonable timeframe. Of course, the maximum number of training iterations is not fixed and may need to be adjusted according to the characteristics of the specific problem and the needs of the actual application. For example, the maximum number of training iterations can also be set to 100, 300, etc., and this invention does not limit this setting.
[0140] In step S2, when the water quality test score is determined to be less than a preset score threshold, an alarm command is generated and sent to the control terminal, so that the control terminal shuts down the corresponding abnormal water source according to the alarm command, including:
[0141] Obtain the water quality test score, current time data, and test location data obtained from the standard water quality test model;
[0142] The water quality test score is compared with a preset score threshold to determine whether the water quality is below the preset score threshold.
[0143] When the water quality test score is determined to be less than the preset score threshold, an alarm command is generated and sent to the control terminal.
[0144] Based on the information in the alarm command, the control terminal determines the abnormal water source that needs to be shut down;
[0145] The control unit performs a shutdown operation to stop the supply of the abnormal water source;
[0146] The alarm command includes the identification information of the abnormal water source, the current water quality test score, the abnormal time data, and the abnormal location data.
[0147] It is important to note that the preset score threshold is a crucial parameter, defining the minimum acceptable level for water quality testing scores. This threshold is typically set based on relevant environmental standards, regulations, or industry guidelines to ensure that water quality meets health and safety requirements. In practice, the score ranges from 0 to 100, where 100 represents the best water quality and 0 represents the worst. Scores above 90 indicate good water quality, 70 to 89 indicate average water quality, 60 to 69 indicate poor water quality, and scores below 60 indicate substandard water quality. The preset score threshold is set to 60. When the water quality testing score falls below this preset threshold, the system automatically generates an alarm command and sends it to the control terminal to stop the supply of the abnormal water source. Of course, the score range can also be set between 0 and 10, and the score threshold can be set to 6 levels. Depending on the application scenario, it can also be set as a discrete level division, such as excellent, good, average, poor, and substandard. This invention does not limit this.
[0148] For example, the preset score threshold is set to 60 points. This means that when the water quality test score is below 60 points, the server will determine that the water quality is abnormal and generate an alarm command. When the water quality test score is below 70 points, the server will automatically trigger the alarm mechanism, generating an alarm command containing abnormal water source identification information, the current water quality test score, abnormal time data, and abnormal location data, and send it to the control terminal. After receiving the alarm command, the control terminal will quickly identify the abnormal water source that needs to be shut down based on the information in the command and execute the shutdown operation to prevent the water quality problem from spreading further and ensure public health and environmental safety.
[0149] In this embodiment, after sending the alarm command to the control terminal so that the control terminal shuts down the corresponding abnormal water source according to the alarm command, the method further includes:
[0150] Send the alarm command to the user terminal;
[0151] The user terminal receives alarm commands, parses and obtains the identification information of abnormal water sources, current water quality test scores, abnormal time data and abnormal location data;
[0152] Based on the identification information of the abnormal water source, the current water quality test score, the abnormal time data, and the abnormal location data, the user terminal notifies the user that the current water source is abnormal, marks the abnormal location, and issues an abnormal alarm.
[0153] It is worth noting that in this embodiment, in addition to sending alarm commands to the control terminal to shut down the abnormal water source, alarm commands are also sent to the user terminal. The purpose of this step is to ensure that users can be promptly informed of the current abnormal status of the water source and take appropriate preventative measures. Upon receiving the alarm command, the user terminal parses the command content to obtain the abnormal water source's identification information, the current water quality test score, the abnormal time data, and the abnormal location data. Based on this information, the user terminal will issue a prompt to the user, informing them that the current water source is abnormal, marking the abnormal location on the user interface, and simultaneously issuing an abnormal alarm so that the user can respond quickly and take necessary actions, such as temporarily stopping the use of the water source to avoid potential health risks. This dual-channel alarm mechanism improves the system's response efficiency and user safety.
[0154] To facilitate understanding of the present invention, some preferred embodiments of the present invention will be described in further detail below.
[0155] In this embodiment, the urban water supply system water quality monitoring involves a monitoring network consisting of a standard water quality testing model, a control terminal, user terminals, and multiple water quality monitoring points. This system aims to monitor the water quality status of various water sources in the city in real time to ensure water supply safety.
[0156] The work process is as follows:
[0157] Step 1: The city's water supply system starts its daily water supply process, and water quality monitoring points begin to work, transmitting real-time water quality data to the server.
[0158] Step 2: The server uses a standard water quality testing model to analyze and calibrate the water quality data, and compares the calibrated water quality score with a preset score threshold.
[0159] Step 3: During the water supply process, a water quality monitoring point detected an abnormal decrease in the water quality score, which fell below the preset score threshold.
[0160] Step 4: The server generates an alarm command and sends it to the water quality monitoring point;
[0161] Step 5: After receiving the alarm command, the water quality monitoring point immediately activates the protection mechanism, such as closing the water supply valve of the water source and issuing an audible and visual alarm;
[0162] Step Six: Based on the location data of the water quality monitoring points, the server marks the alarm location on the water supply map and reduces the water supply pressure at the alarm location to reduce the further spread of water quality problems.
[0163] Step 7: The server sends the alarm information to the user terminal to remind the operator to pay attention and take appropriate emergency measures;
[0164] Step 8: After receiving the alarm information, the operator shall quickly go to the alarm location to check and take emergency measures according to the actual situation, such as evacuating users in the affected area, isolating the source of pollution, or repairing the equipment.
[0165] Step 9: After the problem is properly resolved, the server will recalibrate the water quality monitoring points to ensure the accuracy of the monitoring data and restore normal water supply operations.
[0166] Through the above steps, the urban water supply system can promptly detect and respond to water quality anomalies, ensuring public health and water supply safety.
[0167] To send alarm commands to the control terminal and the user terminal, the following two implementation methods are provided:
[0168] In one implementation, the server sends alarm commands to the control terminal and the user terminal through a communication module configured on the server, so that the control terminal can execute corresponding protection measures according to the received commands and notify the operators to take emergency measures; wherein, the communication module has been pre-connected to the control terminal and the user terminal through a wired network.
[0169] In this implementation, the server's communication module has established a stable communication connection with the control terminal and the user terminal in advance. Once the server detects that the water quality test score is less than the standard water quality score threshold, it will immediately send an alarm command to the control terminal and the user terminal through the wired network. This method sends the information to the user terminal through a dedicated communication network, ensuring the timeliness and reliability of the information.
[0170] In another implementation, the server sends alarm commands to the control terminal and the user terminal through a communication module configured on the server, so that the control terminal can execute corresponding protection measures according to the received commands and notify the operators to take emergency measures; wherein, the communication module has established a connection with the control terminal and the user terminal in advance through a wireless network.
[0171] In this implementation, the communication module of the server has already established a communication connection with the control terminal and the user terminal. Once the server detects that the water quality test score is less than the standard water quality score threshold, it will immediately send an alarm command to the control terminal and the user terminal through the wireless network, so that the operator can receive alarm information anytime and anywhere.
[0172] Reference Figure 4 The second embodiment of the present invention provides a tap water detection system, comprising:
[0173] The detection terminal is used to acquire turbidity data, pH data, water temperature data, dissolved oxygen concentration data, detection location data, and detection time data, and then send the detection data to the server.
[0174] The server is used to process the detection data. The server calculates the water quality detection score based on the standard water quality detection model. When the water quality detection score is determined to be less than a preset score threshold, an alarm command is generated and sent to the control terminal so that the control terminal can shut down the corresponding abnormal water source according to the alarm command.
[0175] The control terminal is used to receive instructions from the server and control the opening and closing of the water source;
[0176] The user terminal is used to receive instructions from the server, obtain detection data from the detection terminal, display the detection status, and when the alarm instruction is received, based on the detection data from the detection terminal, prompt the user that there is an anomaly in the current water source, mark the location of the anomaly, and issue an anomaly alarm.
[0177] It should be noted that the tap water testing system provided in this embodiment of the invention is used to execute all the process steps of the tap water testing method in the above embodiment. The working principles and beneficial effects of the two are one-to-one, so they will not be described again.
[0178] In summary, this invention provides a tap water testing method, comprising: acquiring current turbidity data, current pH data, current water temperature data, and current dissolved oxygen concentration data collected by a data acquisition device, and inputting them into a pre-trained standard water quality testing model to obtain a water quality testing score; when the water quality testing score is determined to be less than a preset score threshold, generating an alarm command and sending the alarm command to a control terminal, so that the control terminal shuts down the corresponding abnormal water source according to the alarm command; wherein, the training process of the standard water quality testing model includes: acquiring historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data; performing data preprocessing and PCA dimensionality reduction on the historical turbidity data, historical pH data, historical water temperature data, and historical dissolved oxygen concentration data to obtain dimensionality-reduced data; based on the dimensionality-reduced data and the preset standard water quality data as input data, constructing an initial water quality testing model based on a particle swarm optimization algorithm, and training the initial water quality testing model according to a membership matrix and a probability partitioning matrix to obtain a standard water quality testing model. The method described above uses a standard water quality detection model trained with historical multidimensional water quality data to detect current water quality data in real time. This eliminates interference from various factors, enables real-time detection of tap water, improves the accuracy of abnormal detection results, and allows for timely warning and handling of abnormal water sources.
[0179] This invention also provides a terminal device. The terminal device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, such as a tap water testing program. When the processor executes the computer program, it implements the steps described in the various tap water testing method embodiments above, for example... Figure 1 The step S11 shown. Alternatively, when the processor executes the computer program, it implements the functions of each module / unit in the above system embodiments.
[0180] For example, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in the terminal device.
[0181] The terminal device may be a desktop computer, laptop, handheld computer, or smart tablet, etc. The terminal device may include, but is not limited to, a processor and memory. Those skilled in the art will understand that the above components are merely examples of terminal devices and do not constitute a limitation on the terminal device. It may include more or fewer components than described above, or a combination of certain components, or different components. For example, the terminal device may also include input / output devices, network access devices, buses, etc.
[0182] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor. The processor is the control center of the terminal device, connecting all parts of the terminal device via various interfaces and lines.
[0183] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the terminal device by running or executing the computer programs and / or modules stored in the memory and by calling data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the mobile phone (such as audio data, phonebook, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0184] Wherein, if the modules / units integrated in the terminal device are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or system capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0185] It should be noted that the system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Furthermore, in the accompanying drawings of the system embodiments provided by this invention, the connection relationships between modules indicate that they have communication connections, which can be specifically implemented as one or more communication buses or signal lines. Those skilled in the art can understand and implement this without any creative effort.
[0186] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the scope of protection of the present invention. In particular, it should be noted that any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the scope of protection of the present invention for those skilled in the art.
Claims
1. A tap water detection method, It is characterized in that Executed by the server, including: Obtain the current turbidity data, current pH data, current water temperature data and current dissolved oxygen concentration data collected by the collection equipment, and input them into the pre-trained standard water quality detection model to obtain the water quality detection score value; When it is determined that the water quality detection score is less than a preset score threshold, an alarm instruction is generated, and the alarm instruction is sent to the control end, so that the control end closes the corresponding abnormal water source according to the alarm instruction; The training process of the standard water quality detection model includes: Obtain historical turbidity data, historical pH data, historical water temperature data and historical dissolved oxygen concentration data; Performing data preprocessing and PCA dimensionality reduction operation on the historical turbidity data, the historical pH data, the historical water temperature data, and the historical dissolved oxygen concentration data to obtain reduced dimensionality data; Based on the dimension reduction data and the preset standard water quality data as input data, an initial water quality detection model is constructed based on a particle swarm algorithm, and the initial water quality detection model is trained according to a membership matrix and a possibility partition matrix to obtain a standard water quality detection model; Wherein, the historical turbidity data, the historical pH data, the historical water temperature data and the historical dissolved oxygen concentration data are subjected to data preprocessing and PCA dimensionality reduction operations to obtain dimensionality reduction data, including: Standardizing the historical turbidity data, the historical pH data, the historical water temperature data, and the historical dissolved oxygen concentration data to obtain standardized data; Calculating the covariance matrix based on the standardized data to obtain a correlation covariance matrix; Performing eigenvalue decomposition according to the correlation covariance matrix to obtain eigenvalues and eigenvectors; According to the eigenvalues and the eigenvectors, a preset number of the eigenvectors are selected in descending order of the eigenvalues to obtain an eigenvector matrix; According to the standardized data and the eigenvector matrix, projecting the standardized data onto the eigenvector matrix to obtain dimension-reduced data; The method comprises: constructing an initial water quality detection model based on a particle swarm algorithm based on the dimension reduction data and the preset standard water quality data as input data, training the initial water quality detection model according to the membership matrix and the possibility partition matrix, and obtaining a standard water quality detection model, including: Initializing the cluster center and the number of clusters of the initial water quality detection model; Initializing a particle swarm according to the cluster center and the cluster number, performing full gradient inertial particle swarm optimization, and obtaining an optimal initial cluster center and an optimal initial cluster number; Initializing the parameters, the membership matrix and the possibility partition matrix of the initial water quality detection model according to the optimal initial cluster center and the optimal initial cluster number; According to the current membership matrix and the possibility partition matrix, cluster centers are updated and trained; When the number of training times is greater than or equal to the preset maximum number of training times, the training is determined to be completed and a standard water quality detection model is obtained; The updating and training of cluster centers according to the current membership matrix and the possibility partition matrix includes: Obtaining the membership matrix and the possibility partition matrix; Perform distance calculation based on the membership matrix and the possibility partition matrix to obtain the distance from each data point to all cluster centers; For each cluster center, a contribution value is calculated according to the membership matrix to obtain a position contribution value of each data point to each cluster center; According to the position contribution value, weighted sum of the position contribution values of all data points is performed to obtain a second cluster center; Recalculate the membership of all data points according to the second cluster center to obtain a second membership matrix and a second possibility partition matrix; Replacing the cluster center, the membership matrix and the possibility partition matrix with the second cluster center, the second membership matrix and the second possibility partition matrix respectively; The step of recalculating the membership of all data points according to the second cluster center to obtain a second membership matrix and a second possibility partition matrix includes: The membership degree is updated by calculating through the following formula: ; in, For the The data points belong to The class membership, For the The data points belong to The class membership, For the The data points belong to The likelihood of the class split, For the The data points belong to The likelihood of the class split, is the number of clusters; The possibility partition matrix is updated by calculating through the following formula: ; in, For the The data points belong to The likelihood of the class split, For data points and The Euclidean distance between cluster centers, For the data points, For the Cluster centers, For the The scale parameter of the class, is the likelihood-weighted index; When it is determined that the water quality detection score is less than a preset score threshold, an alarm instruction is generated, and the alarm instruction is sent to the control end so that the control end closes the corresponding abnormal water source according to the alarm instruction, including: Obtaining a water quality detection score value, current time data, and detection location data obtained from the standard water quality detection model; Compare the water quality detection score with a preset score threshold to determine whether the water quality is lower than the preset score threshold; When it is determined that the water quality detection score is less than a preset score threshold, an alarm instruction is generated and sent to the control terminal; According to the information in the alarm instruction, the control end determines the abnormal water source that needs to be closed; The control end performs a closing operation to stop the supply of the abnormal water source; The alarm instruction includes identification information of the abnormal water source, current water quality detection score value, abnormal time data and abnormal location data.
2. The tap water detection method according to claim 1, It is characterized in that Initializing the particle swarm according to the cluster center and the cluster number, performing full gradient inertial particle swarm optimization, and obtaining the optimal initial cluster center and the optimal initial cluster number, includes: Initializing a particle swarm according to the cluster center and the number of clusters to obtain an initial particle swarm; Calculating the particle inertia weight according to the initial particle group to obtain the inertia weight value of each particle; Calculating the fitness of particles according to the initial particle group to obtain the fitness of each particle; According to the fitness and the inertia weight value of each particle, the particle velocity and the particle position are iterated based on full gradient descent, and when the number of iterations is greater than or equal to the preset maximum number of iterations, the iteration is determined to be completed, and the optimal initial cluster center and the optimal initial cluster number are obtained; The particle position represents the cluster center and the number of clusters of the initial water quality detection model, and the particle speed represents the update step of the cluster center and the number of clusters.
3. The tap water detection method according to claim 1, It is characterized in that After sending the alarm instruction to the control end so that the control end shuts down the corresponding abnormal water source according to the alarm instruction, the method further includes: Sending the alarm instruction to the user terminal; The user end receives the alarm instruction, parses and obtains the identification information of the abnormal water source, the current water quality detection score, the abnormal time data and the abnormal location data; According to the identification information of the abnormal water source, the current water quality detection score value, the abnormal time data and the abnormal location data, the user terminal prompts the user that there is an abnormality in the current water source, marks the abnormal location and issues an abnormal alarm.
4. A tap water detection system, It is characterized in that Used to implement the tap water detection method according to any one of claims 1 to 3, comprising: The detection end is used to obtain turbidity data, pH data, water temperature data, dissolved oxygen concentration data, detection location data and detection time data, and send the detection data to the server end; A service end is used to process the detection data, the service end calculates a water quality detection score value according to a standard water quality detection model, and when it is determined that the water quality detection score value is less than a preset score threshold, generates an alarm instruction, and sends the alarm instruction to the control end, so that the control end closes the corresponding abnormal water source according to the alarm instruction; The control end is used to receive the instruction from the service end and control the opening and closing of the water source; The user end is used to receive instructions from the server end, obtain the detection data from the detection end, and display the detection status. When receiving the alarm instruction, it prompts the user that there is an abnormality in the current water source based on the detection data of the detection end, marks the abnormal location and issues an abnormal alarm.
5. A computer-readable storage medium, It is characterized in that The computer-readable storage medium includes a stored computer program, wherein when the computer program is executed, the device where the computer-readable storage medium is located is controlled to execute the tap water detection method according to any one of claims 1 to 3.
Citation Information
Cited By
Multi-modal sensing and edge intelligence water area monitoring unmanned ship and graded early warning system
CN120496273A
