## 3 Theoretical Background
### Local Outlier Factor  
The LOF method is an unsupervised outlier-detection algorithm that evaluates the local density deviation of a given data point in relation to its neighbors [46]. The key concept is to identify samples that have lower density than their neighbors. The output of the LOF algorithm is a local outlier factor score that reflects the abnormality of observations. The LOF algorithm consists of the following steps: (1) determining the \(k\)-value to select the cluster size; (2) calculating the reachability distance (RD) for each point; (3) calculating the local reachability distance (LRD) value; and (4) calculating the local outlier factor score for each point. For two given data points \(p\) and \(o\), the distance between them in a Euclidean \(n\)-dimensional space can be expressed as:  
\[d(p,o)=\sqrt{\sum_{i=1}^{n}\left(p_{i}-o_{i}\right)^{2}} \tag{1}\]For a given data point \(p\), the \(k-\)distance(\(p\)) is defined as the distance between the point \(p\) and its \(k\)th nearest neighbor. Note that the set of \(k\)-nearest neighbors includes all points at this distance, which may exceed \(k\) points when two or more distances are equal. The symbol \(N_{k}(p)\) represents the set of \(k\)-nearest neighbors and is also known as \(k\)-neighbors. Equation (2) is the reachability distance (RD) of a point \(p\) with regard to any point \(o\). It is defined as the maximum of \(k\)-distance of \(o\) and the distance between point \(p\) and point \(o\) (i.e., \(d(p,o)\)). \[\text{RD}_{k}(p,\;o)=\max(k-distance(o),\;d(p,o)) \tag{2}\]  
If a point \(p\) is located within the \(k\)-neighbors of point \(o\), the RD is the \(k\)-distance of \(o\); otherwise, the RD is set to the actual distance \(d(p,o)\). Figure 3 illustrates the RD of different data points \(p\) in relation to data point \(o\) when \(k\) equals 3 and \(N_{k}(o)\) equals 4. For point \(p_{3}\) in Figure 3, the real distance between \(p_{3}\) and \(o\) is less than the \(k\)-distance(\(o\)); therefore, the RD of point \(p_{3}\) is the \(k\)-distance(\(o\)). In the case of \(p_{5}\), the real distance between \(p_{5}\) and \(o\) is greater than \(k\)-distance(\(o\)), so its RD is the real distance. When the \(k\) value is large, the objects in the same neighborhood will have similar RD values. This smoothing operation is used to alleviate the variation of \(d(p,o)\) for all data points adjacent to point \(o\). However, an algorithm with a high \(k\) value might not recognize local outliers, whereas an algorithm with a small \(k\) value is sensitive to noise. The third step of the LOF algorithm is to compute the LRD value. Equation (3) defines the formula for calculating the LRD for each point. It can be seen that the LRD is the inverse of the average reachability distance of a data point \(p\) from its neighbors. Based on Equation (3), the larger the average RD (i.e., the neighbors are at a greater distance from the point), the smaller the density of points around a particular point. This indicates how far a point is located from the nearest cluster of points. A low LRD means that the nearest cluster is located at a greater distance from the point  
\[\text{LRD}_{k}(p)=\frac{1}{\sum_{o\in N_{k}(p)}\frac{\text{RD}_{k}(p,o)}{\|N_ {k}(p)\|}} \tag{3}\]  
The final step is calculating the LOF score. The formula for calculating the LOF score is defined in Equation (4). It is the ratio of the average LRD of the \(k\)-neighbors of a data point \(p\) to the LRD of \(p\). \[\text{LOF}_{k}(p)=\frac{\sum_{o\in N_{k}(p)}\text{LRD}_{k}(o)}{\|N_{k}(p)\|} \times\frac{1}{\text{LRD}_{k}(p)} \tag{4}\]  
The ratio of the average LRD of neighbors is almost equal to the LRD of a point if the point is a normal instance (since a point has an approximately equal density to its neighbors). In this case, the LOF score is roughly equal to 1. When the point is an outlier, then the LRD of the point will be smaller than the average LRD of neighboring points. In such a case, the LOF score is higher than 1. Figure 3: Reachability distance (RD) when \(k=3\).