# Finsformer: A Novel Approach to Detecting Financial Attacks Using Transformer and Cluster-Attention
## 3 Materials and Methods
### Proposed Method
#### 3.3.3 Cluster-Attention Mechanism
By minimizing the distances between data points and cluster centers, the algorithm can identify inherent patterns in the data. DBSCAN, an algorithm that forms clusters based on the density of data points within a region, is particularly effective for discovering clusters of arbitrary shapes. The algorithmic process is also outlined in Algorithm 2. The algorithm mainly involves two parameters: \(\epsilon\) (neighborhood radius) and \(MinPts\) (minimum number of points in the neighborhood). The logic of the algorithm is as follows: (1) Input and initialization: The algorithm's input includes a dataset of points \(X\), a neighborhood radius \(\epsilon\), and a minimum number of points \(MinPts\). Initially, all data points are marked as unvisited. (2) Traversing data points: For each point \(p\) in the dataset \(X\), if \(p\) has already been visited, the process continues to the next point; otherwise, the following steps are executed. (3) Region query: For each point \(p\), all points within its \(\epsilon\) neighborhood are identified, forming a neighborhood set \(NeighborPts\). (4) Core point determination and cluster expansion: If the number of points in \(NeighborPts\) is less than \(MinPts\), \(p\) is marked as a noise point; otherwise, \(p\) is considered a core point, and a new cluster \(C\) is created for \(p\). Then, the \(expandCluster\) function is called to expand this cluster. (5) Cluster expansion: In the \(expandCluster\) function, for each point \(q\) in \(NeighborPts\), if \(q\) has not been visited, it is marked as visited, and the number of points in the \(\epsilon\) neighborhood of \(q\) is checked. If the number of points in the neighborhood of \(q\) is greater than or equal to \(MinPts\), these new points are added to \(NeighborPts\). If \(q\) does not belong to any known cluster, \(q\) is added to the current cluster \(C\). (6) Output: Finally, the algorithm outputs the cluster labels for each data point. The mathematical description of the above algorithm is as follows: for a given point \(p\), its \(\epsilon\)-neighborhood is defined by  
\[N_{\epsilon}(p)=q\in D|\text{dist}(p,q)\leq\epsilon \tag{10}\]  
where \(D\) is the dataset, and \(\text{dist}(p,q)\) represents the distance between points \(p\) and \(q\). A point \(p\) is a core point if and only if its \(\epsilon\)-neighborhood contains at least \(MinPts\) points, as in  
\[|N_{\epsilon}(p)|\geq MinPts \tag{11}\]  
where \(|N_{\epsilon}(p)|\) denotes the number of points in the \(\epsilon\)-neighborhood of \(p\). For each core point, all points in its \(\epsilon\)-neighborhood (including other core points and boundary points) belong to the same cluster. If the \(\epsilon\)-neighborhood of a core point overlaps with that of another core point, then all points in these neighborhoods are part of the same cluster. ```
Input: Data points \(X\), Radius \(\epsilon\), Minimum points \(MinPts\) Output: Cluster labels for data points  Initialize all points as unvisited for each point \(p\in X\)do if\(p\) is visited then  continue to next point endif  Mark \(p\) as visited \(NeighborPts=\text{regionQuery}(p,\epsilon)\) ifnumber of points in \(NeighborPts<MinPts\)then  Mark \(p\) as noise else \(C=\text{nextCluster}()\)  expandCluster\((p,NeighborPts,C,\epsilon,MinPts)\) endif endfor function expandCluster\((p,NeighborPts,C,\epsilon,MinPts)\) for each point \(q\in NeighborPts\)do if\(q\) is not visited then  Mark \(q\) as visited \(NeighborPts^{\prime}=\text{regionQuery}(q,\epsilon)\) ifnumber of points in \(NeighborPts^{\prime}\geq MinPts\)then \(NeighborPts=NeighborPts\cup NeighborPts^{\prime}\) endif endif if\(q\) is not yet member of any cluster then  Add \(q\) to cluster \(C\) endif endfor function regionQuery\((p,\epsilon)\) return all points within \(p\)'s \(\epsilon\)-neighborhood (including \(p\))
```  
**Algorithm 2** DBSCAN clustering algorithm