Tap water detection method and system and storage medium
By using a pre-trained standard water quality detection model and combining it with the particle swarm algorithm for real-time detection of tap water, it solves the problem of poor real-time detection in the existing technology, achieves high-accuracy abnormal warning and processing, and ensures water quality safety.
Patent Information
- Application Number
- CN202411119703.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-15
- Publication Date
- 2024-09-20
- Estimated Expiration
- 2044-08-15
AI Technical Summary
Existing tap water detection methods have poor real-time performance and the analysis process is susceptible to interference, resulting in low accuracy of abnormal detection results and difficulty in timely warning and handling of abnormal water sources.
Using a pre-trained standard water quality detection model, by obtaining current turbidity, pH value, water temperature and dissolved oxygen concentration data, combined with historical data for data preprocessing and PCA dimensionality reduction, the particle swarm algorithm is used to build an initial model to achieve real-time water quality detection and Generate alarm instructions to shut down abnormal water sources.
It realizes real-time detection of tap water, improves the accuracy of abnormal detection results, can promptly warn and deal with abnormal water sources, and ensures the safety of water supply.
Smart Images

Figure CN118671291A
Abstract
Description
Technical Field
[0001] The present invention relates to the field of water quality detection, and in particular to a tap water detection method, system and storage medium. Background Art
[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 and accuracy of tap water testing are directly related to water quality safety. Especially in the face of sudden pollution incidents, the ability to timely discover and warn of abnormal water sources is an important measure to ensure water supply safety. In addition, with the increasing awareness of environmental protection, water resource management not only needs to pay attention to water quality, but also requires effective monitoring of water volume and analysis of historical data to ensure the sustainable use of water resources.
[0003] The existing technology has proposed a variety of tap water testing methods, including methods based on physical and chemical parameter detection, such as the measurement of pH, turbidity, dissolved oxygen and other indicators. These methods mainly rely on on-site sampling and laboratory analysis.
[0004] In the existing technology, laboratory analysis often takes a long time, and the analysis process is easily affected by various interference factors, resulting in poor real-time detection and low accuracy of abnormal detection results, making it difficult to timely warn and deal with abnormal water sources. Summary of the invention
[0005] The present invention provides a tap water detection method, system and storage medium to achieve real-time detection of tap water, improve the accuracy of abnormal detection results, and enable timely early warning and processing of abnormal water sources.
[0006] In a first aspect, in order to solve the above technical problems, the present invention provides a tap water detection method, comprising: 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 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.
[0007] As an optional implementation manner, 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, the standardized data is projected onto the eigenvector matrix to obtain dimension-reduced data.
[0008] As an optional implementation, the dimension reduction data and the preset standard water quality data are used 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, 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.
[0009] As an optional implementation, the particle swarm is initialized according to the cluster center and the cluster number, and full gradient inertial particle swarm optimization is performed to obtain the optimal initial cluster center and the optimal initial cluster number, including: 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.
[0010] As an optional implementation manner, 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; The cluster center, the membership matrix and the possibility partition matrix are replaced by the second cluster center, the second membership matrix and the second possibility partition matrix respectively.
[0011] As an optional implementation manner, the 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 The scale parameter of the class, is the likelihood weighted index.
[0012] As an optional implementation, 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, and further includes: 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.
[0013] As an optional implementation manner, 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.
[0014] In a second aspect, the present invention provides a tap water detection system, 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.
[0015] In a third aspect, the present invention further provides a computer-readable storage medium, which includes a stored computer program, wherein when the computer program is running, the device where the computer-readable storage medium is located is controlled to execute any one of the tap water detection methods described above.
[0016] Compared with the prior art, the present invention has the following beneficial effects: The present invention provides a tap water detection method, comprising: obtaining current turbidity data, current pH data, current water temperature data and current dissolved oxygen concentration data collected by a collection device, and inputting them into a pre-trained standard water quality detection model to obtain a water quality detection score value; when it is determined that the water quality detection score value is less than a preset score threshold, generating an alarm instruction, and sending the alarm instruction to a control end, so that the control end closes the corresponding abnormal water source according to the alarm instruction; wherein the training process of the standard water quality detection model comprises: obtaining 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 reduced dimensionality data and preset standard water quality data as input data, constructing an initial water quality detection model based on a particle swarm algorithm, and training the initial water quality detection model according to a membership matrix and a possibility partition matrix to obtain a standard water quality detection model. The method uses a standard water quality detection model trained with historical multi-dimensional water quality data to detect current water quality data in real time, thereby eliminating interference from multiple factors, achieving real-time detection of tap water, improving the accuracy of abnormal detection results, and being able to promptly warn and handle abnormal water sources. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a schematic flow chart of a tap water detection method provided by an embodiment of the present invention; Figure 2 is a training schematic diagram of a standard water quality detection model provided by an embodiment of the present invention; Figure 3 It is a flow chart of the PSO-PFCM algorithm provided by an embodiment of the present invention; Figure 4 It is a structural schematic diagram of a tap water detection system provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0018] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0019] 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 and accuracy of tap water testing are directly related to water quality safety. Especially in the face of sudden pollution incidents, the ability to timely discover and warn of abnormal water sources is an important measure to ensure water supply safety. In addition, with the increasing awareness of environmental protection, water resource management not only needs to pay attention to water quality, but also requires effective monitoring of water volume and analysis of historical data to ensure the sustainable use of water resources.
[0020] The existing technology has proposed a variety of tap water testing methods, including methods based on physical and chemical parameter detection, such as the measurement of pH, turbidity, dissolved oxygen and other indicators. These methods mainly rely on on-site sampling and laboratory analysis.
[0021] In the existing technology, laboratory analysis often takes a long time, and the analysis process is easily affected by various interference factors, resulting in poor real-time detection and low accuracy of abnormal detection results, making it difficult to timely warn and deal with abnormal water sources.
[0022] In order to solve the above problems, a tap water detection method provided in the embodiment of the present application will be introduced and explained in detail through the following specific embodiments.
[0023] Reference Figure 1 The first embodiment of the present invention provides a tap water detection method, comprising the following steps: S1, obtaining the current turbidity data, current pH data, current water temperature data and current dissolved oxygen concentration data collected by the collection device, and inputting them into the pre-trained standard water quality detection model to obtain the water quality detection score value; S2, 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.
[0024] In step S1, the current turbidity data, current pH data, current water temperature data and current dissolved oxygen concentration data collected by the collection device are obtained and input into a pre-trained standard water quality detection model to obtain a water quality detection score value.
[0025] It should be noted that turbidity is caused by suspended particles in the water, such as silt, organic matter, and microorganisms. These particles scatter and absorb light, thus affecting the transparency of the water. The pH value is an indicator of the acidity and alkalinity of the water body, which is determined by the concentration of hydrogen ions in the water. Specifically, the pH value of natural water bodies is usually between 6.5 and 8.5. Water temperature is the result of the combined effects of factors such as ambient temperature, solar radiation, and water flow. Water temperature affects the metabolic activity and distribution of aquatic organisms, as well as the rate of chemical reactions in the water body. Monitoring water temperature helps to understand the ecological status and physical and chemical properties of the water body. The dissolved oxygen concentration is determined by factors such as the exchange of oxygen between the water body and the atmosphere and the photosynthesis of aquatic plants. Dissolved oxygen is an essential substance for the survival of aquatic organisms, and its concentration directly affects the ecological health of the water body. These features are acquired in real time by the acquisition equipment and input into the pre-trained standard water quality detection model. The model will output a water quality detection score based on these data. This score is a comprehensive indicator used to quickly assess the overall status of water quality and help decision makers determine whether the water quality meets the standards and whether further measures need to be taken. In this way, real-time monitoring and effective management of water quality can be achieved, ensuring the safety and sustainable use of water resources.
[0026] like Figure 2 As shown, the current turbidity data, current pH data, current water temperature data and current dissolved oxygen concentration data collected by the acquisition device in step S1 are obtained and input into the pre-trained standard water quality detection model to obtain the water quality detection score value, including: S11, obtaining historical turbidity data, historical pH data, historical water temperature data and historical dissolved oxygen concentration data; S12, 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; 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 algorithm, and the initial water quality detection model is trained according to the membership matrix and the possibility partition matrix to obtain a standard water quality detection model.
[0027] Among them, the preset standard water quality data refers to a set of defined reference data for evaluating and comparing water quality conditions. These data usually include a series of water quality parameters, such as pH, dissolved oxygen concentration, water temperature and turbidity, as well as the ideal or allowable ranges of these parameters. In specific applications, the standard water quality data is a pH between 6.5 and 8.5, a dissolved oxygen concentration between 5.0 and 10.0 mg / L, a water temperature between 0 and 30°C, and a turbidity between 0 and 5 NTU. The preset standard water quality data provides a reference benchmark for the model, helping the model learn how to identify and evaluate water quality conditions, and ultimately obtain an accurate and reliable water quality detection model.
[0028] In step S11, historical turbidity data, historical pH data, historical water temperature data and historical dissolved oxygen concentration data are obtained.
[0029] It should be noted that these historical data come from monitoring data from the past five years. The purpose of using historical data to train the standard water quality detection model is to allow the model to learn the complex relationship and changing patterns between water quality parameters. During the training process, the model will try to find the best mapping relationship between input data and output. In this embodiment, the mapping relationship between turbidity, pH value, water temperature and dissolved oxygen concentration and water quality detection score values is found. The trained standard water quality detection model can be used for water quality prediction and evaluation of real-time data, helping to quickly determine the current water quality status.
[0030] In step S12, data preprocessing and PCA dimensionality reduction operation are performed 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, 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, the standardized data is projected onto the eigenvector matrix to obtain dimension-reduced data.
[0031] In the embodiment of the present invention, the calculation formula for the normalization process is: ; in, represents the original data point; Represents the mean of the data set; Represents the standard deviation of the data set; Represents the normalized data points.
[0032] It should be noted that the standardization process is to calculate the mean and standard deviation of each parameter. In this embodiment, the parameters of the standardization process are turbidity, pH value, water temperature and dissolved oxygen concentration. Then, each data is standardized. The purpose of the standardization process is to convert data of different dimensions and ranges to the same dimension so that the data are comparable.
[0033] In the embodiment of the present invention, the calculation formula of the covariance matrix is: ; in, A normalized matrix representing the data; represents the transpose of a normalized matrix; represents the degrees of freedom of the sample covariance; represents the covariance matrix.
[0034] It should be noted that the covariance matrix is a square matrix, which is calculated using standardized data and reflects the correlation between various parameters. Eigenvalue decomposition is the process of decomposing the covariance matrix into eigenvalues and eigenvectors. The eigenvalue represents the variance of each principal component, and the eigenvector represents the direction of the principal component. The purpose of selecting the eigenvector is to retain the most important principal component, and a preset number of eigenvectors are selected in order from large to small according to the eigenvalue, and the eigenvector that can explain most of the variation is usually selected. 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., which is not limited by the present invention. Data projection is to use the selected eigenvector matrix to perform a linear transformation on the standardized data to obtain a new data set, and the dimension of this data set is usually much smaller than the original data. Through this series of data preprocessing and PCA dimensionality reduction operations, the dimension of the data can be effectively reduced while retaining the most important information. The data after dimensionality reduction is easier to process and analyze, which helps to improve the efficiency and accuracy of subsequent model training.
[0035] like Figure 3 As shown, in step S13, the reduced dimension data and the preset standard water quality data are used 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, including: S131, initializing the cluster center and the number of clusters of the initial water quality detection model; S132, initializing a particle swarm according to the cluster center and the number of clusters, performing full gradient inertial particle swarm optimization, and obtaining an optimal initial cluster center and an optimal initial number of clusters; S133, 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; S134, updating and training the cluster centers according to the current membership matrix and the possibility partition matrix; S135, when the number of training times is greater than or equal to the preset maximum number of training times, it is determined that the training is completed and a standard water quality detection model is obtained.
[0036] It should be noted that the cluster center and the number of clusters are key parameters of the initial water quality detection model. The cluster center defines the aggregation point of the data, and the number of clusters determines the number of clusters. The initial cluster center and the initial number of clusters are obtained by random initialization or based on prior knowledge, and are used to define the relationship between the input and output of the model. The cluster center is continuously adjusted during the model training process to determine the center of normal water quality data, so as to eliminate various interference factors, realize real-time detection of tap water, improve the accuracy of abnormal detection results, and timely warn and deal with abnormal water sources.
[0037] In step S132, a particle swarm is initialized according to the cluster center and the cluster number, and full gradient inertial particle swarm optimization is performed to obtain an optimal initial cluster center and an optimal initial cluster number, including: 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.
[0038] In the embodiment of the present invention, the calculation formula for calculating the inertia weight is as follows: ; in, is the new inertia weight; is the detection function value of the current iteration.
[0039] In the embodiment of the present invention, the detection function is as follows: ; in, represents the individual optimal solution; represents the global optimal solution; Indicates The particle in The position at the iteration; and represents the Euclidean distance between the two; Indicates The detection function value of iteration.
[0040] In the embodiment of the present invention, the updating formula for updating the speed and position of the particle is as follows: ; ; in, represents the inertia weight; Indicates the number of iterations; Indicates The current velocity of a particle at the kth iteration; Indicates The current velocity of a particle at the k+1th iteration; Indicates The current position of a particle at the kth iteration; Indicates The current position of a particle at the k+1th iteration; The value is 2, indicating the self-learning factor; The value is 2, indicating the social learning factor; The value range is [0, 1], indicating a random factor; The value range is [0, 1], indicating a random factor; represents the individual optimal solution; It represents the global optimal solution, which embodies the idea of full gradient descent method.
[0041] It is worth noting that the preset maximum number of iterations is a key parameter that determines the convergence speed of the algorithm and the quality of the final solution. If it is set too small, the algorithm may converge too early and fail to find the global optimal solution; if it is set too large, although a better solution may be found, the computational cost and time consumption will increase. 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., which is not limited in the present invention.
[0042] In step S134, cluster centers are updated and trained according to the current membership matrix and the possibility partition matrix, including: 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; The cluster center, the membership matrix and the possibility partition matrix are replaced by the second cluster center, the second membership matrix and the second possibility partition matrix respectively.
[0043] Among them, data points are the basic units in cluster analysis, and they represent individuals that need to be classified or grouped. In this embodiment, the pH value, dissolved oxygen, turbidity and water temperature of each detection point constitute a data point after PCA dimension reduction. These data points are clustered to identify abnormal points or outliers in the data, thereby determining whether the water quality is abnormal.
[0044] It is worth noting that the membership matrix is a two-dimensional matrix, in which each row corresponds to a data point and each column corresponds to a cluster center. Each element in the matrix represents the membership or probability that the data point belongs to a certain cluster center. The membership value is usually between 0 and 1, indicating the degree to which the data point belongs to the cluster center. The membership matrix is usually generated by a certain initialization method in the initial stage of the clustering algorithm, or calculated by the update rule in the iterative process. The initialization method can be a random assignment or based on some prior knowledge of the data point. The membership matrix is used to determine the relationship between the data point and the cluster center during the clustering process. Through the membership matrix, the contribution value of each data point to each cluster center can be calculated, and then the position of the cluster center can be updated. Exemplarily, the possibility partition matrix is similar to the membership matrix and is also a two-dimensional matrix, but it is usually used to represent the uncertainty or possibility that the data point belongs to a certain cluster center. The elements in the possibility partition matrix represent the possibility or confidence that the data point belongs to a certain cluster center. The possibility partition matrix is derived from the membership matrix through a certain probability model or uncertainty measurement method. It reflects the possibility of a data point belonging to each cluster center given a membership matrix. The possibility partition matrix is used in the clustering process to enhance the robustness and reliability of the clustering results. By considering the possibility of a data point belonging to each cluster center, the clustering results can be more comprehensively evaluated and optimized.
[0045] In this embodiment, the membership degree is updated by calculating using 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; In this embodiment, the possibility partition matrix is updated by 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 The scale parameter of the class, is the likelihood weighted index.
[0046] In step S135, when the number of training times is greater than or equal to the preset maximum number of training times, it is determined that the training is completed and a standard water quality detection model is obtained.
[0047] It is worth noting that the preset maximum number of training times is a key parameter, which determines when the training process of the possibility fuzzy C clustering is terminated. In the present embodiment, the preset maximum number of training times is set to 200 times, which is the result of experimental verification, ensuring that a standard water quality detection model with acceptable performance is obtained within a reasonable time. Of course, the maximum number of training times is not fixed, and may need to be adjusted accordingly according to the characteristics of specific problems and the needs of practical applications. For example, the maximum number of training times can also be set to 100, 300, etc., and the present invention is not limited to this.
[0048] In step S2, 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 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.
[0049] It should be noted that the preset score threshold is a key parameter that defines the minimum acceptable level of the water quality detection score. This threshold is usually set based on relevant environmental standards, regulations or industry guidelines to ensure that the water quality meets health and safety requirements. In a specific implementation, the score range is between 0 and 100, where 100 represents the best water quality and 0 represents the worst water quality. 90 points or more represent good water quality, 70 to 89 points represent general water quality, 60 to 69 points represent poor water quality, and 60 points or less represent unqualified water quality. The preset score threshold is set to 60. When the water quality detection score is lower than this preset score threshold, the system will automatically generate an alarm instruction and send it to the control end to stop the supply of the abnormal water source. Of course, the score range can also be set to between 0 and 10, and the score threshold can be set to 6, etc. It can also be set to discrete level divisions according to different application scenarios, such as excellent, good, general, poor and unqualified, and the present invention is not limited to this.
[0050] Exemplarily, the preset score threshold is set to 60 points, which means that when the water quality test score is lower than 60 points, the server will determine that the water quality condition is abnormal and generate an alarm instruction. When the water quality test score is lower than 70 points, the server will automatically trigger the alarm mechanism, generate an alarm instruction containing abnormal water source identification information, current water quality test score, abnormal time data and abnormal location data, and send it to the control end. After receiving the alarm instruction, the control end will quickly determine the abnormal water source that needs to be closed based on the information in the instruction, and perform the closing operation to prevent the water quality problem from spreading further and ensure public health and environmental safety.
[0051] In this embodiment, 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.
[0052] It is worth noting that in this embodiment, in addition to sending an alarm instruction to the control end to shut down the abnormal water source, an alarm instruction is also sent to the user end. The purpose of this step is to ensure that the user can promptly understand the abnormal condition of the current water source and take corresponding preventive measures. After receiving the alarm instruction, the user end will parse the instruction content to obtain the identification information of the abnormal water source, the current water quality detection score, the abnormal time data and the abnormal location data. Based on this information, the user end will issue a prompt to the user to inform that the current water source is abnormal, mark the abnormal location on the user interface, and issue 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 response efficiency of the system and the safety of users.
[0053] In order to facilitate the understanding of the present invention, some preferred embodiments of the present invention are further described below.
[0054] In this embodiment, the water quality monitoring of the urban water supply system involves a monitoring network consisting of a standard water quality detection model, a control terminal, a user terminal and multiple water quality detection points. The system is designed to monitor the water quality of each water source point in the city in real time to ensure water supply safety.
[0055] The working process is as follows: Step 1: The city water supply system starts the daily water supply process, the water quality detection point starts working, and transmits real-time water quality data to the server; Step 2: The server uses the standard water quality detection model to analyze and calibrate the water quality data, and compares the calibrated water quality score with the preset score threshold; Step 3: During the water supply process, a water quality detection point detects that the water quality score value is abnormally reduced and is lower than the preset score threshold; Step 4: The server generates an alarm instruction and sends it to the water quality detection point; Step 5: After receiving the alarm command, the water quality detection point immediately activates the protection mechanism, such as closing the water supply valve of the water source point and issuing an audible and visual alarm; Step 6: The server marks the alarm location on the water supply map based on the location data of the water quality detection point, and reduces the water supply pressure at the alarm location to reduce the further spread of the water quality problem; Step 7: The server sends the alarm information to the user to remind the operator to pay attention and take corresponding emergency measures; Step 8: After receiving the alarm information, the operator will 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 pollution source or repairing the equipment; Step 9: After the problem is properly resolved, the service end recalibrates the water quality detection point to ensure the accuracy of its monitoring data and resumes normal water supply operations.
[0056] Through the above steps, the urban water supply system can promptly detect and respond to water quality anomalies to protect public health and water supply safety.
[0057] In order to send alarm instructions to the control end and the user end, the following two implementation methods are provided: In one embodiment, the server sends an alarm instruction to the control terminal and the user terminal through a communication module configured on the server, so that the control terminal executes corresponding protection measures according to the received instructions and notifies the operator to take emergency measures; wherein the communication module is pre-connected with the control terminal and the user terminal through a wired network.
[0058] In this embodiment, the communication module of the server has established a stable communication connection with the control end and the user end in advance. Once the server detects that the water quality detection score is lower than the standard water quality score threshold, it will immediately send an alarm instruction to the control end and the user end through the wired network. This method sends the information to the user end through a dedicated communication network to ensure the timeliness and reliability of the information.
[0059] In another embodiment, the server sends an alarm instruction to the control end and the user end through a communication module configured on the server end, so that the control end executes corresponding protection measures according to the received instructions and notifies the operator to take emergency measures; wherein the communication module establishes a connection with the control end and the user end in advance through a wireless network.
[0060] In this embodiment, the communication module of the server has established a communication connection with the control end and the user end in advance. Once the server detects that the water quality detection score is less than the standard water quality score threshold, it will immediately send an alarm instruction to the control end and the user end through the wireless network, so that the operator can receive the alarm information anytime and anywhere.
[0061] Reference Figure 4 The second embodiment of the present invention provides a tap water detection system, 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.
[0062] It should be noted that a tap water detection system provided in an embodiment of the present invention is used to execute all process steps of a tap water detection method in the above embodiment, and the working principles and beneficial effects of the two correspond one to one, so they will not be repeated here.
[0063] In summary, the present invention provides a tap water detection method, comprising: obtaining current turbidity data, current pH data, current water temperature data and current dissolved oxygen concentration data collected by a collection device, and inputting them into a pre-trained standard water quality detection model to obtain a water quality detection score; when it is determined that the water quality detection score is less than a preset score threshold, generating an alarm instruction, and sending the alarm instruction to a control end, so that the control end closes the corresponding abnormal water source according to the alarm instruction; wherein the training process of the standard water quality detection model comprises: obtaining historical turbidity data, historical pH data, historical water temperature data and historical dissolved oxygen concentration data; performing data preprocessing and PCA dimensionality reduction operations 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 reduced dimensionality data and preset standard water quality data as input data, constructing an initial water quality detection model based on a particle swarm algorithm, and training the initial water quality detection model according to a membership matrix and a possibility partitioning matrix to obtain a standard water quality detection model. The method uses a standard water quality detection model trained with historical multi-dimensional water quality data to detect current water quality data in real time, thereby eliminating interference from multiple factors, achieving real-time detection of tap water, improving the accuracy of abnormal detection results, and being able to promptly warn and handle abnormal water sources.
[0064] The embodiment of the present invention further 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 detection program. When the processor executes the computer program, the steps in the above-mentioned tap water detection method embodiments are implemented, such as Figure 1 Alternatively, the processor implements the functions of each module / unit in the above-mentioned system embodiments when executing the computer program.
[0065] Exemplarily, the computer program may be divided into one or more modules / units, which are stored in the memory and executed by the processor to implement the present invention. The one or more modules / units may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the terminal device.
[0066] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, and a smart tablet. The terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art will appreciate that the above components are merely examples of terminal devices and do not constitute a limitation on the terminal device. The terminal device may include more or fewer components than the above components, or may combine certain components, or different components. For example, the terminal device may also include input and output devices, network access devices, buses, etc.
[0067] The processor may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the terminal device, and uses various interfaces and lines to connect various parts of the entire terminal device.
[0068] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the terminal device by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area can store data created according to the use of the mobile phone (such as audio data, a phone book, etc.), etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0069] Wherein, if the module / unit integrated in the terminal device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on such an understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Wherein, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or system capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased 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 electric carrier signals and telecommunication signals.
[0070] It should be noted that the system embodiment described above is merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the system embodiment provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. A person of ordinary skill in the art may understand and implement it without paying any creative effort.
[0071] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present invention. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. It is particularly pointed out that for those skilled in the art, any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention should be included in the scope of protection of the present invention.
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 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.
2. The tap water detection method according to claim 1, It is characterized in that 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, the standardized data is projected onto the eigenvector matrix to obtain dimension-reduced data.
3. The tap water detection method according to claim 1, It is characterized in that The method uses the dimension reduction data and the preset standard water quality data as input data, constructs an initial water quality detection model based on a particle swarm algorithm, and trains the initial water quality detection model according to a membership matrix and a possibility partition matrix to obtain 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.
4. The tap water detection method according to claim 3, 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.
5. The tap water detection method according to claim 3, It is characterized in that 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; The cluster center, the membership matrix and the possibility partition matrix are replaced by the second cluster center, the second membership matrix and the second possibility partition matrix respectively.
6. The tap water detection method according to claim 5, It is characterized in that 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 is updated by calculating 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 The scale parameter of the class, is the likelihood weighted index.
7. The tap water detection method according to claim 1, It is characterized in that 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.
8. 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.
9. A tap water detection system, It is characterized in that include: 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.
10. 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 8.
Citation Information
Patent Citations
Circulating aquaculture dissolved oxygen prediction control method, device, equipment and medium
CN114611336A
Water quality monitoring stationing optimization method based on RF-C-SOM clustering algorithm
CN118171136A
IoT system that can improve and manage water quality in real time and predict climate change
KR102296505B1
Cited By
Optical fiber performance evaluation method and system based on environmental conditions and storage medium
CN119249116A
Determination method and system for on-site detection of hydrogeological parameters
CN120046377A
