# Data Cleaning Model of Mine Wind Speed Sensor Based on LOF-GMM and SGAIN
## 2 LOF-GMM-SGAIN Model  
### Real-Time Anomaly Data Detection  
In reference [12], several unsupervised anomaly detection algorithms are proposed. After careful consideration, this paper selected the LOF algorithm for anomaly detection. The LOF algorithm, as an unsupervised anomaly detection method [22], calculates a score to reflect the degree of anomaly of a sample. This score is the ratio of the average density of the samples in the neighborhood of a given point to the density at the point's location. Based on the data density, it determines whether the point is an anomaly. The process begins by calculating the local outlier factor (LOF) for the neighboring samples and then compares the LOF value with a predefined threshold to identify whether the point is an anomaly. The specific application process of the LOF algorithm is as follows:  
(1) Calculate the k-reachability distance for each sample point  
In an n-dimensional space, the distance between data point \(P\) and its k-th nearest neighbor is referred to as the k-nearest neighbor distance of point \(P\). If point \(O\) is the k-th nearest point to point \(P\), then the k-nearest neighbor distance of point \(P\), denoted as \(d_{k}(P)\), is expressed by the following formula:  
\[d_{k}(P)=d(P,O) \tag{1}\]  
In the formula, \(d(P,O)\) represents the Euclidean distance from point \(P\) to point \(O\). With point \(P\) as the center and \(d_{k}(P)\) as the radius, a circle is drawn such that point \(O^{\prime}\) is inside the circle. The area within this circle constitutes the k-distance neighborhood \(N_{\text{k}}(P)\), expressed mathematically as follows:  
\[N_{\text{k}}(P)=\left\{d(P,O^{\prime})\leq d_{k}(P)\right\} \tag{2}\]  
In the formula, \(d(P,O^{\prime})\) represents the Euclidean distance from point \(P\) to point \(O^{\prime}\). The k-reachable distance from point \(P\) to point \(O\) is defined as follows:  
\[d_{k}(O,P)=\max\{d_{k}(O),d(O,P)\} \tag{3}\]  
In the formula, \(d_{k}(O)\) denotes the k-nearest distance of point \(O\), and \(d(O,P)\) represents the Euclidean distance from point \(O\) to point \(P\). (2) Calculate the local reachability density  
The local reachability density (LRD) of point P is defined as the reciprocal of the average reachable distance from point P to its k-nearest neighbors. The specific formula is as follows:  
\[\rho_{k}(P)=\frac{1}{\frac{\sum_{O\
i N_{k}(P)}d_{k}(P,O)}{|N_{k}(P)|}}=\frac{ |N_{k}(P)|}{\sum_{O\
i N_{k}(P)}d_{k}(P,O)} \tag{4}\]  
(3) Calculate the local outlier factor (LOF) value for each data point in the sample sequence. The local outlier factor (LOF) is defined using local density. The LOF of a data point P is the ratio of the average local reachability density of all points in the k-neighborhood of P to the local reachability density of P. The formula is as follows:  
\[LOF_{k}(P)=\frac{\sum_{O\
i N_{k}(P)}\frac{\rho_{k}(O)}{\rho_{k}(P)}}{|N_{k}(P )|}=\frac{\sum_{O\
i N_{k}(P)}\rho_{k}(O)}{|N_{k}(P)|}/\rho_{k}(P) \tag{5}\]  
In the formula, \(LOF_{k}(P)\) represents the average ratio of the local reachability density of points within the k-distance neighborhood \(N_{k}(P)\) of point \(P\) to the local reachability density of \(P\). A larger \(LOF_{k}(P)\) value indicates a higher likelihood that point \(P\) is an outlier. After obtaining the LOF values for all data points, a Gaussian mixture model (GMM) is used to cluster the LOF values. This approach automatically determines the anomaly threshold. Gaussian mixture clustering is a probabilistic model-based clustering algorithm. It assumes that each cluster is composed of multiple Gaussian distributions, meaning the data points in each cluster are sampled from different Gaussian distributions. In a Gaussian mixture model (GMM), each cluster is defined by three parameters: a mean vector, a covariance matrix, and a weight. The objective of the Gaussian mixture clustering algorithm is to maximize the log-likelihood function.