A method and device for detecting abnormality of safety water equipment

Through the combination of FastDTW oversampling and GWO-Randomforest and GAT-DiffusionVAE algorithms, the problem of high computational complexity of large-scale data sets in the existing technology is solved, efficient anomaly detection of safe water equipment is achieved, and known and unknown anomalies are identified. , improving detection accuracy and efficiency.

CN118606872BActive Publication Date: 2024-10-11HUAQIAO UNIVERSITY +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411080347.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-08
Publication Date
2024-10-11
Estimated Expiration
2044-08-08

AI Technical Summary

Technical Problem

Existing anomaly detection technology has high computational complexity when processing large-scale data sets, resulting in long time consumption and difficulty in adapting to the needs of actual industrial systems.

Method used

FastDTW oversampling method is used to balance anomaly categories, combined with GWO-Randomforest and GAT-DiffusionVAE algorithms, divided into supervised and unsupervised anomaly detection, known anomalies are identified through FastDTW-GWO-Randomforest filter, and unknown anomalies are identified using GAT-DiffusionVAE , improve detection efficiency and accuracy.

Benefits of technology

It effectively identifies known and unknown anomalies, improves the accuracy of overall anomaly detection, solves the problem of abnormal category imbalance in supervised detection and insufficient utilization of sensor correlation relationships in unsupervised detection, and improves detection efficiency and accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118606872B_ABST
    Figure CN118606872B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and device for detecting anomalies of safety water equipment, comprising constructing a detection model, wherein the construction process specifically comprises the following steps: (1) obtaining historical characteristic data of the safety water equipment; (2) preprocessing the data to obtain the processed data; (3) dividing the data set into a training set, a validation set and a test set; (4) dividing the training set into two parts, one for a training set of a supervised anomaly detection classification algorithm and the other for a training set of an unsupervised anomaly detection algorithm; (5) for the training set of the supervised anomaly detection classification algorithm, using FastDTW to oversample the anomaly data to construct an anomaly class balanced data set; (6) for the training set of the unsupervised anomaly detection algorithm, filtering out the anomaly data in the training set; (7) using the training set of the supervised anomaly detection classification algorithm to train a supervised GWO-Randomforest anomaly detection algorithm; and (8) using the training set of the unsupervised anomaly detection algorithm to train an unsupervised GAT-DiffusionVAE anomaly detection algorithm.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of anomaly detection, and in particular to a detection model for anomaly of safety water equipment and a method and device for anomaly detection. Background Art

[0002] Safety water equipment plays a key role in many industries, but its performance will decline due to long-term operation and complex environment, causing failures and downtime. This poses a threat to the production efficiency and product quality of enterprises. At present, enterprises mainly rely on regular maintenance and manual diagnosis to manage these devices, but these methods have limitations.

[0003] The normal operation of safety water equipment is the key to ensuring the orderly progress of industrial processes, and anomaly detection plays a vital role in the entire industrial production process. Therefore, the use of efficient anomaly detection technology to diagnose faults in industrial equipment and the use of different sensors to detect anomalies in the collected industrial equipment data can not only improve the detection efficiency, but also prevent safety accidents caused by equipment failures, and provide guarantees for the continuous and stable operation of industrial equipment. In the process of industrial construction, anomaly detection can not only help enterprises prevent potential crises and discover abnormal equipment, but also timely avoid and reduce the probability of accidents, ensure the continuous and stable progress of industrial processes, and create good economic benefits.

[0004] Existing anomaly detection technologies are mainly divided into three types: purely supervised anomaly detection models, purely unsupervised anomaly detection models, and hybrid methods of the two. Purely supervised anomaly detection models perform anomaly detection by establishing machine learning or deep learning models. Although they have high accuracy, they require a lot of expert experience and prior knowledge, and can only detect known anomalies, making it difficult to adapt to complex systems. Purely unsupervised anomaly detection models perform unsupervised anomaly detection by establishing clustering models based on traditional statistical models, machine learning, or deep learning generative models. Although they do not require a lot of expert experience and can detect unknown anomalies, they have lower accuracy for known anomalies than supervised anomaly detection models, making them difficult to adapt to actual industrial systems.

[0005] The existing hybrid method based on supervised anomaly detection and unsupervised anomaly detection cannot effectively detect known anomalies and unknown anomalies, and has a high time cost, making it difficult to adapt to actual industrial systems. Summary of the invention

[0006] The technical problem to be solved by the present invention is to solve the problem that the prior art directly applies clustering algorithms to large-scale data sets, which may lead to high computational complexity and long time consumption.

[0007] The present invention adopts the following technical solution: a detection model for abnormality of safety water equipment, comprising the following steps:

[0008] (1) Obtain historical characteristic data of safety water equipment;

[0009] (2) Preprocess the data and obtain the processed data;

[0010] (3) Divide the dataset into training set, validation set and test set;

[0011] (4) Divide the training set into two parts, one for the supervised anomaly detection classification algorithm and the other for the unsupervised anomaly detection algorithm;

[0012] (5) For the training set of the supervised anomaly detection classification algorithm, FastDTW is used to oversample the anomaly data and construct a data set with balanced anomaly categories;

[0013] (6) For the training set of the unsupervised anomaly detection algorithm, filter out the abnormal data in the training set;

[0014] (7) Use the training set of the supervised anomaly detection classification algorithm to train the supervised GWO-Randomforest anomaly detection algorithm;

[0015] (8) Use the training set of the unsupervised anomaly detection algorithm to train the unsupervised GAT-DiffusionVAE anomaly detection algorithm;

[0016] (9) First, the preprocessed test set is used for supervised anomaly detection and classification based on GWO-Randomforest; the detected abnormal data are classified as known anomalies, and the detected normal data are further subjected to unsupervised anomaly detection based on GAT-DiffusionVAE, and the detected abnormal data are classified as unknown anomalies, and the remaining data are regarded as normal data; the model is tested until the trained model meets the requirements, otherwise the model is retrained; the accuracy, precision, recall rate, and F1-score of the test results are used to determine whether the model is qualified.

[0017] Preferably, step (2) comprises the following steps: filtering out missing values ​​in the data set and filling them with the data of the last non-missing time point. If the missing data is at the first time point, the next non-missing time point is used for filling. The label Normal / Attack value is regarded as abnormal data, and the label Normal / Attack value is regarded as normal data. The label value of Attack is replaced with 1, and the label value of Normal is replaced with 0. That is, the label value of 0 represents normal data, and the label value of 1 represents abnormal data.

[0018] Preferably, step (7) comprises the following steps: calculating the optimal hyperparameters through GWO, using a loss function to measure the difference between the model's prediction and the true label during training, and using the loss function to perform gradient descent update on the model parameters to train and optimize the model, thereby establishing a nonlinear mapping relationship between the input features and the anomaly labels, and obtaining a supervised anomaly detection model after training.

[0019] Preferably, the step (8) comprises the following steps:

[0020] The graph attention mechanism GAT is used to construct the correlation graph between sensors, and then the DiffusionVAE model is used as the generation model to reconstruct the data. During training, the loss function is used to measure the difference between the real data and the reconstructed data of the model, and the loss function is used to perform gradient descent update on the model parameters to train and optimize the model, thereby establishing a nonlinear mapping relationship between the input features and the reconstructed data, and obtaining the GAT-DiffusionVAE reconstruction model after training; the reconstruction loss is used as the anomaly score of the generation model, and the K-means algorithm is used to calculate the adaptive threshold in the validation set. In the test task, GAT-DiffusionVAE is used to reconstruct the test set data, and the reconstruction loss is used as the anomaly score. The anomaly score of the test set is compared with the adaptive threshold. If the anomaly score is higher than the adaptive threshold, it is judged as an anomaly, otherwise it is judged as normal data, and the unsupervised GAT-DiffusionVAE anomaly detection model after training is obtained.

[0021] Preferably, the k-means algorithm is used to calculate the adaptive threshold in the validation set, comprising the following steps: dividing the validation set into two clusters, calculating the centers of the two clusters, and taking the average of the centers of the two clusters as the adaptive threshold.

[0022] Preferably, the K-means algorithm uses a distance metric to calculate the similarity between data points and cluster centers; the distance metric is the Euclidean distance: ; In the formula, For distance, yes The data point at the time, is the cluster center, yes The moment The normalized value of the feature, is the cluster center No. The normalized value of the feature, 9 is the number of features;

[0023] In the K-means algorithm, for each data point in the data set, the nearest cluster center is selected as its cluster assignment. ;in: ; In the formula, For distance, yes The data point at the time, is the cluster center;

[0024] The cluster center in the K-means clustering algorithm is the average of the feature values ​​of all data points assigned to the cluster; for each cluster center, its value is updated as: , where is the new cluster center, Belongs to the cluster A collection of data points, yes Data point at a moment.

[0025] Preferably, the step (9) comprises the following steps:

[0026] The preprocessed test set is first input into the supervised anomaly detection classifier for anomaly detection to obtain the anomaly category label corresponding to each test sample in the test set; the detected abnormal data is classified as known anomalies, and the detected normal data is further input into the unsupervised anomaly detection model for anomaly detection to obtain the anomaly category label of each data sample, and the detected abnormal data is classified as unknown anomalies, and the detected normal data is classified as normal; according to the warning level label corresponding to each test sample, the accuracy, precision, recall rate Recall and F1 score of the overall abnormal category and normal category, as well as the F1-score for known anomalies and the F1-score for unknown anomalies are calculated:

[0027] Comprehensively consider the accuracy, precision, recall and F1 score to determine whether the model is qualified. If the model is qualified, the pre-trained safe water treatment anomaly and unknown anomaly detection model based on supervised filtering and unsupervised model is obtained. Otherwise, the model is retrained.

[0028] The calculation rules for the overall abnormal category and normal category accuracy, precision, recall rate Recall and F1 score are as follows:

[0029] First, classify both known anomalies and unknown anomalies as anomalies, and classify the normal category as normal;

[0030] The formula for calculating accuracy is: ;

[0031] The formula for calculating precision is: ;

[0032] The formula for calculating the Recall rate is: ;

[0033] The formula for calculating F1 score is: .

[0034] Among them, TP represents the number of true positives, that is, the actual situation and the test result are both normal samples; FP represents the number of false positives, that is, the actual situation is an abnormal sample and the test result is a normal sample; TN represents the number of true negatives, that is, the actual situation and the test situation are both abnormal samples; FN represents the number of false negatives, that is, the actual situation is a normal sample and the test result is an abnormal sample;

[0035] The calculation rules for the F1-score of known anomalies and the F1-score of unknown anomalies are as follows: for the F1-score of known anomalies, only the F1-score scores of the true anomaly categories of known anomalies and normal are calculated; for the F1-score of unknown anomalies, only the F1-score scores of the true anomaly categories of unknown anomalies and normal are calculated.

[0036] A method for detecting abnormality of safety water equipment comprises the following steps:

[0037] The detection data of the safety water equipment is obtained and preprocessed; the preprocessing step is: filtering out the missing values ​​in the data set and filling them with the data of the last non-missing time point. If the missing data is at the first time point, the next non-missing time point is used for filling, and the preprocessed detection data is input into the detection model as described above to obtain the abnormal detection results.

[0038] A safety water equipment abnormality detection device comprises a processor, a memory, and a computer program stored in the memory; the computer program can be executed by the processor to implement a safety water equipment abnormality detection method as described above.

[0039] The present invention has the following beneficial effects: the present invention combines the FastDTW oversampling method, the GWO Grey Wolf hyperparameter optimization method, the Randomforest random forest anomaly detection classification algorithm, the graph attention network GAT algorithm, and the DiffusionVAE algorithm, and uses the FastDTW-GWO-Randomforest-based supervised anomaly detection model as a filter to effectively identify known anomalies, and then uses the GAT-DiffusionVAE-based unsupervised anomaly detection model to perform anomaly detection, effectively identifying unknown anomalies. Compared with traditional methods, this method can not only effectively identify known anomalies and unknown anomalies, but also improve the accuracy of overall anomaly detection, and effectively solve the problem of anomaly category imbalance faced by supervised anomaly detection models and the problem of insufficient utilization of the correlation between sensors and low precision faced by unsupervised anomaly detection models. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0041] Figure 1 It is a schematic diagram of the process of abnormal detection of safety water equipment of the present invention.

[0042] Figure 2 It is a schematic diagram of the training process of the safety water equipment anomaly detection model of the present invention.

[0043] Figure 3 This is a flowchart of the training process of the supervised filter GWO-Randomforest model.

[0044] Figure 4 This is a flowchart of the training and testing process of the unsupervised anomaly detection model GAT-DiffusionVAE.

[0045] Figure 5 It is a model architecture diagram of safe water treatment anomaly and unknown anomaly detection based on an unsupervised model with supervised filtering in an embodiment of the present invention. DETAILED DESCRIPTION

[0046] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are 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 making creative work belong to the scope of protection of the present invention. Therefore, the following detailed description of the embodiments of the present invention provided in the drawings is not intended to limit the scope of the invention claimed for protection, but merely represents the selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work belong to the scope of protection of the present invention.

[0047] In the description of the present invention, it should be understood that the terms "center", "longitudinal", "lateral", "length", "width", "thickness", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside", "outside", "clockwise", "counterclockwise" and the like indicate orientations or positional relationships based on the orientations or positional relationships shown in the accompanying drawings, and are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the referred device or element must have a specific orientation, be constructed and operated in a specific orientation, and therefore should not be understood as a limitation on the present invention.

[0048] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. In the description of the present invention, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.

[0049] In the present invention, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.

[0050] In the present invention, unless otherwise clearly specified and limited, a first feature being "above" or "below" a second feature may include that the first and second features are in direct contact, or may include that the first and second features are not in direct contact but are in contact through another feature between them. Moreover, a first feature being "above", "above" and "above" a second feature includes that the first feature is directly above and obliquely above the second feature, or simply indicates that the first feature is higher in level than the second feature. A first feature being "below", "below" and "below" a second feature includes that the first feature is directly below and obliquely below the second feature, or simply indicates that the first feature is lower in level than the second feature.

[0051] Example

[0052] The following are only preferred implementations of the present invention. The protection scope of the present invention is not limited to the following embodiments. All technical solutions under the concept of the present invention belong to the protection scope of the present invention.

[0053] See also Figures 1 to 5As shown, the first embodiment of the present invention provides a method for detecting anomalies and unknown anomalies in safe water treatment based on an unsupervised model with supervised filtering. The method can be performed by a device for detecting anomalies and unknown anomalies in safe water treatment based on an unsupervised model with supervised filtering (hereinafter referred to as a pre-device). In particular, the method is performed by one or more processors in the pre-device to implement steps F1 to F2.

[0054] F1. Obtain monitoring data of safety water equipment and perform pre-processing.

[0055] Specifically, the steps of preprocessing the monitoring data are the same as the steps of preprocessing the test set, including steps S2 to S6.

[0056] F2. Input the pre-processed monitoring data into the pre-trained safe water treatment anomaly and unknown anomaly detection model based on the unsupervised model with supervised filtering to obtain the anomaly label.

[0057] Specifically, the pre-trained safety water treatment anomaly and unknown anomaly detection model based on supervised filtering and unsupervised model has established a nonlinear mapping relationship between input features and anomaly labels. By inputting the pre-processed monitoring data into the model, the anomaly label at the current moment can be output, where the anomaly label is a label containing normal or abnormal. Therefore, it is of great practical significance to detect whether the running equipment has anomalies based on historical monitoring data and avoid unnecessary losses caused by sudden downtime.

[0058] Preferably, Figure 2 As shown, the safety water treatment anomaly and unknown anomaly detection model based on the unsupervised model with supervised filtering is obtained by training based on steps S1 to S9.

[0059] S1. Obtain historical characteristic data of safety water equipment.

[0060] Specifically, the historical feature data of the safety water equipment includes 127 status information of the safety water equipment during operation, data from 123 sensors and actuators, a total of 16 consecutive days of data, 14 days of normal operation, and 2 days of periodic abnormal state attacks. The time granularity is 1s, and the historical feature data of this time period is obtained;

[0061] It is understandable that the pre-device may be an electronic device with computing capabilities, such as a portable notebook computer, a desktop computer, a server, a smart phone, or a tablet computer.

[0062] S2, preprocessing the historical feature data,

[0063] Specifically, the missing values ​​in the data set are screened out and filled with the data from the last non-missing time point. If the missing data is at the first time point, the next non-missing time point is used for filling, and the label Normal / Attack value is Attack as abnormal data, and the label Normal / Attack value is Normal as normal data. The label value of Attack is replaced with 1, and the label value of Normal is replaced with 0. That is, the label value of 0 represents normal data, and the label value of 1 represents abnormal data.

[0064] S3. Divide the dataset into training set, validation set and test set.

[0065] Specifically, the data set was collected from December 22, 2015 to January 2, 2016. The abnormal attack types include single-stage single-point attack, single-stage multi-point attack, multi-stage single-point attack, and multi-stage multi-point attack.

[0066] The data from December 22, 2015 to December 28, 2015 are used as the training set, which contains normal data and abnormal data. The abnormal data are all single-stage single-point attack types.

[0067] The data from December 29, 2015 to December 30, 2015 are divided into a validation set, which includes normal data and abnormal data. The abnormal data types include single-stage single-point attack, single-stage multi-point attack, multi-stage single-point attack, and multi-stage multi-point attack.

[0068] The data from December 31, 2015 to January 2, 2016 are used as the test set. The test set includes normal data and abnormal data. The abnormal types include single-stage single-point attack, single-stage multi-point attack, multi-stage single-point attack, and multi-stage multi-point attack.

[0069] In the data set, the anomaly types that appeared in the training set are regarded as known anomalies, that is, the data of single-stage single-point attack types are regarded as known anomalies, and the remaining attack types are unknown anomalies.

[0070] S4. Divide the training set into two parts, one for the supervised anomaly detection classification algorithm and the other for the unsupervised anomaly detection algorithm.

[0071] Specifically, the training set is copied, one copy is used as the training set for the supervised anomaly detection classification algorithm, and the other copy is used as the training set for the unsupervised anomaly detection algorithm.

[0072] S5. For the training set of the supervised anomaly detection classification algorithm, FastDTW is used to oversample the anomaly data and construct a data set with balanced anomaly categories.

[0073] Specifically, since the anomaly categories of the anomaly detection task are extremely unbalanced, the FastDTW oversampling method is used to oversample the anomaly data. Since the time complexity of the DTW oversampling method is ,Therefore, FastDTW is used to optimize the DTW oversampling method, which reduces the time complexity to O(N) and realizes the rapid construction of a balanced data set.

[0074] The steps of DTW oversampling method are as follows:

[0075] 1) Determine the total number of minority class samples that need to be generated

[0076]

[0077] in , Respectively represent the number of minority and majority class samples in the original data; It is the adjustment degree, usually set to 1.

[0078] 2) For each minority class sample , calculate the DTW distance and regularized path between it and other samples, find the k nearest neighbor samples of the sample according to the DTW distance sorting, and calculate the ratio:

[0079]

[0080] in, for The number of samples belonging to the minority class among the nearest neighbor samples.

[0081] 3) Set the threshold , according to the threshold value Divided into two sets of values, corresponding to two different regions of the sample set: the noise set and security set Considering that the noise set contains erroneous sensitive information, which is not conducive to the learning process of the model, the minority class samples belonging to the noise set do not participate in the artificial sample synthesis process.

[0082] 4) Standardized security set The ratio distribution of the sample is obtained , considering that the ratio may be too small, resulting in excessive neglect of samples, an exponential function is used for smoothing correction:

[0083] .

[0084] 5) Determine the number of samples: for each minority sample in the security set , the number of sampling samples is:

[0085]

[0086] in, Indicates rounding up. Note that if the total number of samples obtained by sampling exceeds the set number of samples G, the simple random sampling method is used to eliminate the redundant samples.

[0087] 6) Sampling process: for each minority class sample in the security set , randomly select a minority class sample from its k nearest neighbor samples , let the sample sequence and The dynamic time warping path is , where the synchronization point , n is the length of the sample sequence. The specific steps are as follows:

[0088] Step 1: Interpolate between the synchronization points of the regular path to generate new sample points. However, since the regular path has one-to-one, one-to-many, and many-to-one situations, when calculating the sample value of the interpolation point, the same interpolation operation needs to be performed on the sampling time point for subsequent adjustment:

[0089]

[0090]

[0091] in, A new sample sequence obtained by path interpolation , P is the sampling time point corresponding to the new sample sequence , is (0, ) , , are the minority class samples corresponding to the synchronization points on the DTW path. , its nearest neighbor minority class sample The sample value sequence of ; are the minority class samples corresponding to the synchronization points on the DTW path. , A sequence of points.

[0092] Step 2: Adjust the sampling time point. Due to the existence of one-to-one, one-to-many, and many-to-one regular paths, the sampling intervals of the interpolated sample points may be unequal in length or inconsistent with the sampling intervals of the original sequence. Adjust to the sampling time of the original data

[0093] Step 3: Repeat steps 1 and 2 until the generated samples.

[0094] 7) Repeat step 6) until a specified number of samples are generated around each minority class sample in the security set.

[0095] The FastDTW oversampling method steps are as follows:

[0096] This paper uses FastDTW to calculate DTW distance and regular path, optimizes the calculation speed of DTW, and achieves the purpose of quickly building a balanced data set. The specific algorithm is as follows:

[0097] Coarse-graining. Perform data abstraction on the original time series data to obtain a coarse-grained data set. Each coarse-grained data point represents multiple fine-grained data points (each coarse-grained data point can be the average of multiple fine-grained data points). Projection. Use the standard DTW algorithm to calculate the regularized path on the coarse-grained data set after data abstraction. That is, find the alignment path of the sample sequence on the coarse-grained data set: fine-graining. Adjust the regularized path obtained on the coarse-grained data set to a finer-grained space through local adjustment. Specifically, find the optimal path in the finer-grained space on the neighbor cost matrix unit of the regularized path in the coarse-grained space. The size of the neighbor can be adjusted by the radius parameter (similar to the window width of the restriction method). S6. For the training set of the unsupervised anomaly detection algorithm, filter out the abnormal data in the training set.

[0098] Specifically, by filtering out the data with an abnormal label value of 1, the abnormal data is deleted, so that the data in the unsupervised anomaly detection training set are all normal data.

[0099] S7. Use the training set of the supervised anomaly detection classification algorithm to train the supervised GWO-Randomforest anomaly detection algorithm. GWO-RandomForest (Grey Wolf Optimizer-Random Forest) is an anomaly detection classifier that combines the grey wolf optimization algorithm and random forest. The model training and testing process is as follows Figure 3 shown.

[0100] Specifically, the first step is to define the hyperparameter space. Determine the random forest hyperparameters that need to be optimized and their search space. The hyperparameters optimized by this method include the number of trees and the maximum depth of the tree.

[0101] The second step is to initialize the gray wolf optimization algorithm. First, initialize the wolf pack and randomly generate the initial wolf pack. Each individual represents a hyperparameter combination. Set parameters such as population size and maximum number of iterations. Initialize α, β, and δ wolves, and select the three individuals with the highest fitness from the initial wolf pack as α, β, and δ wolves.

[0102] The third step is to evaluate the fitness. Train the random forest and use the current individual hyperparameter combination to train the random forest classifier. Use the validation set to evaluate the classifier performance, usually using accuracy as the fitness function.

[0103] The fourth step is iterative optimization. The steps of evaluating and updating the position are repeated until the maximum number of iterations or convergence conditions are reached.

[0104] Finally, the final model is trained. Using the hyperparameter combination optimized by GWO, the final random forest model is trained on the entire training set. This model is used as a supervised anomaly detection model.

[0105] S8. Use the training set of the unsupervised anomaly detection classification algorithm to train the unsupervised GAT-DiffusonVAE anomaly detection algorithm. GAT-DiffusionVAE (Graph Attention Network-Diffusion VariationalAutoencoder) is an anomaly detection model that combines the graph attention network (GAT) and the diffusion variational autoencoder (DiffusionVAE). The model training and testing process is as follows Figure 4 shown.

[0106] Specifically, the first step is to build a graph structure, connecting all sensor points to create a fully connected structure.

[0107] The second step is to calculate the attention weights between each node in the graph through the graph attention mechanism. The specific formula is:

[0108]

[0109] in, and is the feature vector of nodes i and j, is a trainable weight vector, Represents a vector concatenation operation.

[0110] Normalize the weights and normalize the attention weights:

[0111]

[0112] in, Represents the neighbor set of node i.

[0113] Update node features using normalized attention weights:

[0114]

[0115] in, is the ReLU activation function, is a trainable weight matrix.

[0116] In the third step, the node features generated by the graph attention network are input into the DiffusionVAE generation model to calculate the reconstruction error.

[0117] The fourth step is to train the final model. Use a gradient descent optimization algorithm (such as Adam) to minimize the loss function and update the model parameters. Through continuous iterative optimization, the final GAT-DiffusionVAE model is obtained.

[0118] The fifth step is to calculate the adaptive threshold of the validation set using the k-means method.

[0119] Among them, the k-means method is used to calculate the adaptive threshold in the validation set, that is, the purpose is to divide the validation set into two clusters, calculate the centers of the two clusters, and use the average value of the centers of the two clusters as the adaptive threshold.

[0120] The K-means clustering algorithm uses a distance metric to calculate the similarity between data points and cluster centers; the distance metric is the Euclidean distance: ; In the formula, For distance, yes The data point at the time, is the cluster center, yes The moment The normalized value of the feature, is the cluster center No. The normalized value of the feature, 9 is the number of features;

[0121] In the K-means clustering algorithm, for each data point in the data set, the closest cluster center is selected as its cluster assignment. ;in: ; In the formula, For distance, yes The data point at the time, is the cluster center;

[0122] The cluster center in the K-means clustering algorithm is the average of the feature values ​​of all data points assigned to the cluster; for each cluster center, its value is updated as: , where is the new cluster center, Belongs to the cluster A collection of data points, yes Data point at a moment.

[0123] In the sixth step, the GAT-DiffusionVAE algorithm is used as the generation algorithm, the reconstruction error is used as the anomaly score, the anomaly score is compared with the adaptive threshold, and the final anomaly result is determined. The final unsupervised anomaly detection model based on GAT-DiffusionVAE is obtained.

[0124] S9. Use the preprocessed test set to first perform supervised anomaly detection classification based on GWO-Randomforest. The detected abnormal data is classified as known anomalies, and the detected normal data is further subjected to unsupervised anomaly detection based on GAT-DiffusionVAE. The detected abnormal data is classified as unknown anomalies, and the remaining data is regarded as normal data. Test the model until the trained model meets the requirements. The model testing process is as follows: Figure 5 shown.

[0125] Specifically, the test data set is input into the safe water treatment anomaly and unknown anomaly detection method based on the unsupervised model with supervised filtering to obtain the anomaly category label corresponding to each test sample in the test set. Then, according to the sample anomaly category label, the accuracy, precision, recall rate Recall and F1 score are calculated. Finally, the accuracy, precision, recall rate Recall and F1 score are comprehensively considered to determine whether the model is qualified. If the model is qualified, the final safe water treatment anomaly and unknown anomaly detection model based on the unsupervised model with supervised filtering is obtained. If the model is unqualified, the model is retrained.

[0126] The calculation rules for the overall abnormal category and normal category accuracy, precision, recall rate Recall and F1 score are as follows:

[0127] First, classify both known anomalies and unknown anomalies as anomalies, and classify the normal category as normal.

[0128] The formula for calculating accuracy is: ;

[0129] The formula for calculating precision is: ;

[0130] The formula for calculating the Recall rate is: ;

[0131] The formula for calculating F1 score is: .

[0132] Among them, TP represents the number of true positive samples, that is, the actual situation and the test result are both normal samples; FP represents the number of false positive samples, that is, the actual situation is an abnormal sample and the test result is a normal sample;

[0133] TN represents the number of true negative examples, that is, both the actual situation and the detected situation are abnormal samples; FN represents the number of false negative examples, that is, the actual situation is a normal sample but the detected result is an abnormal sample;

[0134] The calculation rules for the F1-score of known anomalies (single-stage single-point attack type) and the F1-score of unknown anomalies (single-stage multi-point attack, multi-stage single-point attack, multi-stage multi-point attack) are as follows:

[0135] For known anomalies (single-stage single-point attack type), the F1-score only calculates the F1-score scores of the true anomaly categories as known anomalies (single-stage single-point attack type) and normal ones. For unknown anomalies (single-stage multi-point attack, multi-stage single-point attack, multi-stage multi-point attack), the F1-score only calculates the F1-score scores of the true anomaly categories as unknown anomalies (single-stage multi-point attack, multi-stage single-point attack, multi-stage multi-point attack) and normal ones.

[0136] Specifically, when the accuracy, precision, recall and F1 score are lower than the preset values, the trained model meets the requirements. The preset values ​​are set by those skilled in the art according to actual needs, and the present invention does not specifically limit this.

[0137] In order to verify the effectiveness of the model and model solution proposed in this invention, the historical operation data of the safety water equipment is selected as the research object, and the data information includes the data collected from December 22, 2015 to January 2, 2016. The abnormal attack types include single-stage single-point attack, single-stage multi-point attack, multi-stage single-point attack, and multi-stage multi-point attack.

[0138] The data from December 22, 2015 to December 28, 2015 are used as the training set, which contains normal data and abnormal data. The abnormal data are all single-stage single-point attack types.

[0139] The data from December 29, 2015 to December 30, 2015 are divided into a validation set, which includes normal data and abnormal data. The abnormal data types include single-stage single-point attack, single-stage multi-point attack, multi-stage single-point attack, and multi-stage multi-point attack.

[0140] The data from December 31, 2015 to January 2, 2016 are used as the test set. The test set includes normal data and abnormal data. The abnormal types include single-stage single-point attack, single-stage multi-point attack, multi-stage single-point attack, and multi-stage multi-point attack.

[0141] In the data set, the anomaly types that appeared in the training set are regarded as known anomalies, that is, the data of single-stage single-point attack types are regarded as known anomalies, and the remaining attack types are unknown anomalies.

[0142] The experimental parameters of the present invention are set as shown in Table 1 below:

[0143] Table 1 Experimental parameter settings

[0144]

[0145] The calculation formula of the evaluation method of the model of the present invention is as follows:

[0146] The formula for calculating accuracy is: ;

[0147] The formula for calculating precision is: ;

[0148] The formula for calculating the Recall rate is: ;

[0149] The formula for calculating F1 score is: .

[0150] Among them, TP represents the number of true positive samples, that is, the actual situation and the test result are both normal samples; FP represents the number of false positive samples, that is, the actual situation is an abnormal sample and the test result is a normal sample;

[0151] TN represents the number of true negative examples, that is, both the actual situation and the detected situation are abnormal samples; FN represents the number of false negative examples, that is, the actual situation is a normal sample but the detected result is an abnormal sample;

[0152] The calculation rules for the F1-score of known anomalies (single-stage single-point attack type) and the F1-score of unknown anomalies (single-stage multi-point attack, multi-stage single-point attack, multi-stage multi-point attack) are as follows:

[0153] For known anomalies (single-stage single-point attack type), the F1-score only calculates the F1-score scores of the true anomaly categories as known anomalies (single-stage single-point attack type) and normal ones. For unknown anomalies (single-stage multi-point attack, multi-stage single-point attack, multi-stage multi-point attack), the F1-score only calculates the F1-score scores of the true anomaly categories as unknown anomalies (single-stage multi-point attack, multi-stage single-point attack, multi-stage multi-point attack) and normal ones.

[0154] The FastDTW-GWO-Randomforest algorithm is used to train the supervised anomaly detection model and test the model, and its performance is observed, as shown in Table 2.

[0155] Table 2 Experimental results of FastDTW-GWO-Randomforest algorithm

[0156]

[0157] The GAT-DiffusionVAE algorithm is used to train the unsupervised anomaly detection model and test the model to observe its performance, as shown in Table 3.

[0158] Table 3 Experimental results of GAT-DiffusionVAE algorithm

[0159]

[0160] The unsupervised GAT-DiffusionVAE anomaly detection model based on the supervised anomaly detection filter of FastDTW-GWO-Randomforest is used to train and test the model and observe its performance, as shown in Table 4.

[0161] Table 4 Experimental results of unsupervised model algorithm based on supervised filtering

[0162]

[0163] In summary, the safety water treatment anomaly and unknown anomaly detection model based on the unsupervised model of supervised filtering provided by the present invention can not only detect known anomalies with high accuracy, but also effectively detect unknown anomalies, and at the same time improve the F1-score of the overall anomaly detection. The model solves the problem of extremely unbalanced anomaly categories faced by supervised anomaly detection by using FastDTW, and also uses GWO to optimize the Randomforest anomaly detection classifier, thereby improving the recognition accuracy of the supervised anomaly detection model. The graph attention network GAT is used to construct the association relationship diagram between sensors, and DiffusionVAE is used as the generation model, which not only focuses on the operating status characteristics of the equipment, but also incorporates the time dependency factor, so that the correlation of equipment data over time can be deeply mined. The model can automatically extract key features from multidimensional time series data, discover potential patterns in the data, and effectively capture the relationship between different features, making the model more expressive. The model can capture the contextual information in the historical data, generate a higher level of sequence data representation, and resist the influence of noise, thereby significantly improving the detection accuracy.

[0164] Specifically, the present invention uses a safe water treatment anomaly and unknown anomaly detection model based on an unsupervised model with supervised filtering, which can not only detect known anomalies with high accuracy, but also effectively detect unknown anomalies, while improving the F1-score of the overall anomaly detection.

[0165] The present invention uses FastDTW oversampling to oversample abnormal data, realizes the rapid construction of an abnormal analogy balanced data set, and solves the problem of extremely unbalanced abnormality categories faced by supervised anomaly detection.

[0166] The Grey Wolf hyperparameter optimization method GWO is used to optimize the RandomForest anomaly detection classifier, which improves the recognition accuracy of the supervised anomaly detection model.

[0167] The graph attention network GAT is used to construct the correlation diagram between sensors, and DiffusionVAE is used as the generation model. It not only focuses on the operating status characteristics of the equipment, but also incorporates the time dependency factors, so as to deeply explore the correlation of equipment data changing over time.

[0168] By combining the supervised anomaly detection algorithm with the unsupervised anomaly detection algorithm, the present invention provides a more powerful anomaly detection model. The model can not only detect known anomalies with high accuracy, but also effectively detect unknown anomalies, while improving the F1-score of the overall anomaly detection. At the same time, the unsupervised anomaly detection model can handle complex nonlinear relationships and can also adapt to the time dynamic changes in the data. This provides a new and effective method for the maintenance and health management of mechanical equipment.

[0169] Embodiment 2: The embodiment of the present invention provides a safe water treatment anomaly and unknown anomaly detection device based on an unsupervised model with supervised filtering, which includes a processor, a memory, and a computer program stored in the memory.

[0170] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with the technology to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the protection scope of the present invention. Any equivalent changes or modifications made according to the spirit of the present invention should be included in the protection scope of the present invention.

Claims

1. A method for constructing a detection model for abnormal safety water equipment, characterized in that: The construction method comprises the following steps: (1) Obtaining historical characteristic data of the safety water equipment; specifically, obtaining data of multiple sensors and actuators for multiple consecutive days, wherein the data for multiple consecutive days includes normal data and abnormal data, and obtaining the historical characteristic data of the safety water equipment based on the data for multiple consecutive days; (2) Preprocess the data and obtain the processed data; (3) Divide the dataset into training set, validation set and test set; (4) Divide the training set into two parts, one for the supervised anomaly detection classification algorithm and the other for the unsupervised anomaly detection algorithm; (5) For the training set of the supervised anomaly detection classification algorithm, FastDTW is used to oversample the anomaly data and construct a data set with balanced anomaly categories; (6) For the training set of the unsupervised anomaly detection algorithm, filter out the abnormal data in the training set; (7) Training a supervised GWO-Randomforest anomaly detection algorithm using the training set of the supervised anomaly detection classification algorithm; the training of the supervised GWO-Randomforest anomaly detection algorithm comprises the following steps: 7.1 Define the hyperparameter space first: determine the random forest hyperparameters that need to be optimized and their search space; 7.2 Initialize the gray wolf optimization algorithm: First, initialize the wolf pack and randomly generate the initial wolf pack. Each individual represents a hyperparameter combination. Set the population size and the maximum number of iterations. Select the three individuals with the highest fitness from the initial wolf pack as α, β, and δ wolves respectively. 7.3 Evaluate fitness: Train the random forest, use the current individual hyperparameter combination to train the random forest classifier, use the validation set to evaluate the classifier performance, and use the random forest classifier accuracy as the fitness function; 7.4 Iterative optimization: Update the position of the wolves according to the fitness of each wolf until the maximum number of iterations is reached to obtain the optimized hyperparameter combination; 7.5 Finally, train the final model: Use the hyperparameter combination optimized by GWO to train the final random forest model on the entire training set, and use this model as a supervised anomaly detection model; (8) Training an unsupervised GAT-DiffusionVAE anomaly detection algorithm using the training set of the unsupervised anomaly detection algorithm; the training of the unsupervised GAT-DiffusionVAE anomaly detection algorithm comprises the following steps: 8.1 Build graph structure: connect all sensor points to make a fully connected structure; 8.2 Calculate the attention weights between each node in the graph through the graph attention mechanism, normalize the attention weights, and use the normalized attention weights to update the node features; 8.3 Input the node features generated by the graph attention network into the DiffusionVAE generation model and calculate the reconstruction error; 8.4 Train the final model: Use the gradient descent optimization algorithm to minimize the loss function, update the model parameters, and obtain the final GAT-DiffusionVAE model through continuous iterative optimization; 8.5 Use K-means algorithm to calculate the adaptive threshold of the validation set; 8.6 Use the GAT-DiffusionVAE algorithm as the generation algorithm, the reconstruction error as the anomaly score, compare the anomaly score with the adaptive threshold, determine the final anomaly result, and obtain the final GAT-DiffusionVAE-based unsupervised anomaly detection model; (9) First, the preprocessed test set is used for supervised anomaly detection and classification based on GWO-Randomforest; the detected abnormal data are classified as known anomalies, and the detected normal data are further subjected to unsupervised anomaly detection based on GAT-DiffusionVAE, and the detected abnormal data are classified as unknown anomalies, and the remaining data are regarded as normal data; the detection model is tested until the trained detection model meets the requirements, otherwise the detection model is retrained; among them, the accuracy, precision, recall rate, and F1-score of the test results are used to judge whether the detection model is qualified.

2. The method for constructing a detection model for abnormality of safety water equipment according to claim 1, characterized in that: The K-means algorithm is used to calculate the adaptive threshold in the validation set, including the following steps: dividing the validation set into two clusters, calculating the centers of the two clusters, and taking the average value of the centers of the two clusters as the adaptive threshold.

3. The method for constructing a detection model for abnormality of safety water equipment according to claim 2, characterized in that: The K-means algorithm uses a distance metric to calculate the similarity between data points and cluster centers; the distance metric is the Euclidean distance: ; In the formula, For distance, yes The data point at the time, is the cluster center, yes The moment The normalized value of the feature, is the cluster center No. The normalized value of the feature, 9 is the number of features; In the K-means algorithm, for each data point in the data set, the nearest cluster center is selected as its cluster assignment. ;in: ; In the formula, For distance, yes The data point at the time, is the cluster center; In the K-means algorithm, the cluster center is the average of the feature values ​​of all data points assigned to the cluster; for each cluster center, its value is updated as: , where is the new cluster center, Belongs to the cluster A collection of data points, yes Data point at a moment.

4. The method for constructing a detection model for abnormality of safety water equipment according to claim 1, characterized in that: The step (9) comprises the following steps: The preprocessed test set is first input into the supervised anomaly detection model for anomaly detection to obtain the anomaly category label corresponding to each test sample in the test set; the detected abnormal data is classified as known anomalies, and the detected normal data is further input into the unsupervised anomaly detection model for anomaly detection to obtain the anomaly category label of each data sample, and the detected abnormal data is classified as unknown anomalies, and the detected normal data is classified as normal; According to the warning level label corresponding to each test sample, calculate the accuracy, precision, recall and F1 score of the overall abnormal category and normal category, as well as the F1-score for known abnormalities and the F1-score for unknown abnormalities; Comprehensively consider the accuracy, precision, recall and F1 score to determine whether the detection model is qualified. If the detection model is qualified, the pre-trained detection model is obtained. Otherwise, the detection model is retrained. The calculation rules for the overall abnormal category and normal category accuracy, precision, recall rate Recall and F1 score are as follows: First, classify both known anomalies and unknown anomalies as anomalies, and classify the normal category as normal; The formula for calculating accuracy is: ; The formula for calculating precision is: ; The formula for calculating the Recall rate is: ; The formula for calculating F1 score is: ; Among them, TP represents the number of true positives, that is, the actual situation and the test result are both normal samples; FP represents the number of false positives, that is, the actual situation is an abnormal sample and the test result is a normal sample; TN represents the number of true negatives, that is, the actual situation and the test situation are both abnormal samples; FN represents the number of false negatives, that is, the actual situation is a normal sample and the test result is an abnormal sample; The calculation rules for the F1-score of known anomalies and the F1-score of unknown anomalies are as follows: for the F1-score of known anomalies, only the F1-score scores of the true anomaly categories of known anomalies and normal are calculated; for the F1-score of unknown anomalies, only the F1-score scores of the true anomaly categories of unknown anomalies and normal are calculated.

5. A method for detecting abnormality of safety water equipment, characterized in that: The steps include: Obtain the detection data of the safety water equipment and perform preprocessing. The preprocessing steps are as follows: filter out the missing values ​​in the data set and fill them with the last non-missing time point data; The preprocessed detection data is input into the detection model to obtain the abnormality detection result, and the detection model is constructed by the construction method of the detection model of the abnormality of the safety water equipment according to any one of claims 1 to 4.

6. A safety water equipment abnormality detection device, characterized in that: It comprises a processor, a memory, and a computer program stored in the memory; the computer program can be executed by the processor to implement a method for detecting an abnormality of a safety water device as claimed in claim 5.