## 3 Specification Mining Based on the OPTICS Clustering Algorithm and Model Checking
### Clustering  
In order to create an automaton that captures the specification of the target library classes, the feature values in set \(O\) generated by DSM are clustered to generate FSAs, where \(O\) = \(\{o_{1}=\langle B_{1},A_{1}\rangle,\ldots,o_{h}=\langle B_{h},A_{h}\rangle\}\) as defined in Section 2.2. To do that, some variables used in the clustering algorithm are defined as follows:  
1. \(Cq\), \(Rq\), and \(eps\) are defined as in Section 2.2;
2. \(Kq\) is used to store objects of the same class as a given object;
3. \(K\) is used to mark the category to which the current objects belong;
4. The map \(Labels\) is used to map the category \(K\) to the corresponding core objects at one clustering;
5. \(All\_labels\) is used to store \(Labels\) after each clustering;
6. The variable \(num\) is used to control the increment of \(eps\) at each clustering;
7. \(Plot\) represents the reachability plot generated by the OPTICS clustering algorithm. In order to alleviate the influence of clustering parameters on the clustering results, we first use the OPTICS clustering algorithm shown in Section 2.2 to generate the reachability plot, and then determine the range of \(eps\) and the value of \(num\) based on the plot. Further, we cluster objects in \(O\) according to \(eps\) and \(num\) to generate FSAs. Algorithm 1 shows the clustering process. It takes the feature values in \(O\) extracted by DSM as the input, and outputs a set \(All\_labels\) storing well-classified feature values after multiple clustering. In the algorithm, we first initialize \(Cq\), \(Kq\), \(Rq\), \(Labels\), and \(All\_labels\) to \(\emptyset\), and \(eps\) to \(inf\) (Line 1). Then, the reachability plot \(Plot\) is generated based on OPTICS clustering algorithm \(OPTICS\_RPlot(O)\), the details of which are shown in Section 2.2 (Line 2). The purpose of generating \(Plot\) is to observe the shape and trend in order to determine the appropriate range \([a,b]\) of \(eps\) and the increment value \(num\) of \(eps\) for each time of clustering (Line 3). In order to obtain \(All\_labels\), which is required to generate FSAs, we cluster the feature values in \(O\) with \(eps\) ranging from \(a\) to \(b\) (Lines 4-22). For each clustering time, we first find all core objects needed for clustering from \(O\) and add them to \(Cq\) (Line 6). Then, we cluster the core objects in \(Cq\) to obtain \(Labels\). The following is the process of how we generate \(Labels\). We first find objects whose distances to \(Cq[0]\) are not greater than \(eps\) in \(Cq\) (except \(Cq[0]\)), and add them to \(Kq\), which stores objects of the same category as \(Cq[0]\). Then, we remove \(Cq[0]\) from \(Cq\) and put it in \(Rq\). The distance is the Euclidean distance between two feature values, i.e., two objects (Lines 9-10). Further, we find the core objects in \(Cq\) that belong to the same class as each object in \(Kq\), and add these objects to \(Kq\) until all objects in \(Kq\) are processed. Each time the objects added to \(Kq\) should be deleted from \(Cq\) to avoid duplication, and the objects that have been processed in \(Kq\) should also be removed and added to \(Rq\) (Lines 11-14). When \(Kq\) is empty, we mark the objects in \(Rq\) as class \(K\) and set \(Rq\) to empty in order to continue classifying the remaining objects in \(Cq\) (Lines 15-16). When \(Cq\) is empty, a clustering of objects in \(Cq\) is completed. We add \(Labels\) to \(All\_labels\) and set \(Labels\) to empty for generating the next \(Labels\) (Lines 19-21). Finally, we construct FSAs based on \(All\_lables\) according to the method in [9]. Figure 4 shows an FSA generated based on the OPTICS clustering algorithm. In the FSA, the start state is \(q_{0}=C_{1}\) and the set of acceptable states is \(F=\{C_{4}\}\). The input character table \(\Sigma\) is a collection of methods, \(Q\) is a collection of all states, and each transition between method and its connected states makes up the transition function \(\delta\).