# Dissimilarity Space Based Multi-Source Cross-Project Defect Prediction
## 3 DM-CPDP Approach
### Dissimilarity Space Construction
#### 3.1.1 Prototype Selection  
To select the representative samples as the prototype from the target set, we use the clustering method to select the cluster center as the prototype sample to form the prototype set. Traditional clustering methods require defining the number of clusters artificially, and they cannot select all representative samples in the dataset. So we use the DPC method to cluster samples in this stage. The cluster center has two characteristics: high density and large distance. Cluster centers are surrounded by neighbors with lower local density and relatively large distances from other high-density points.  
In the first step, we calculate the local density \(\rho_{i}\) and local distance \(\delta_{i}\) for each point.  
The \(\rho_{i}\) is equal to the number of points that are closer than \(d_{c}\) to point \(i\). The local density calculation method is as follows:  
\[\rho_{i}=\sum_{j}\chi\big{(}d_{ij}-d_{c}\big{)} \tag{2}\]  
The distance \(d_{ij}\) between sample points is measured by Euclidean distance. \(d_{c}\) is the cutoff distance which ensures each point has at least 2% of the total points as its neighbors, and \(d_{c}>0\). Where \(\chi(x)=1\) if \(x<0\) and \(\chi(x)=0\) otherwise.  
The local distance calculation method is as follows:  
\[\left\{\begin{array}{l}\delta_{i}=\max_{j}(d_{ij}),\qquad\text{if $x_{i}$ has the max $imum$\,$\rho_{i}$}\\ \delta_{i}=\max_{j\in\rho_{i}>\rho_{i}}(d_{ij}),\qquad\text{otherwise}\end{array}\right. \tag{3}\]  
The local distance has two cases: when the point \(x_{i}\) with highest local density, \(\delta_{i}\) is the greatest possible distance with others; otherwise, \(\delta_{i}\) is the distance from \(x_{i}\) to the nearest data point with greater local density.  
Then, the cluster center is selected by considering \(\delta_{i}\) and \(\rho_{i}\) in combination, and the method is shown in Formula (4). \(\delta_{i}\) and \(\rho_{i}\) maybe in different orders of magnitude, we normalize these two quantities, \(z(\cdot)\) is the normalized process. As shown in Figure 2, the points are sorted in descending order of \(\gamma_{i}\) and represented in the form of a graph. The value of the non-cluster centers are relatively smooth and there is a clear jump from the non-cluster center to the cluster center. The points above the inflection point are chosen as the cluster centers.  
\[\gamma_{i}=z(\rho_{i})\times z(\delta_{i}) \tag{4}\]  
Figure 2: Cluster center selection diagram. (a) is the descending arrangement diagram of \(\gamma_{i}\); (b) is the display of the cluster center point selected by the graph (a) in the data sample.  
The method is shown in Algorithm 1. In step 3-7, we calculate the distance between samples, and sort the values of distance in ascending order. Then, the value of the 2%_th_ data are selected as the cut-off distance \(d_{c}\) in step 6-9. In step 10-14, the local density \(\rho_{i}\) and local distance \(\delta_{i}\) are calculated for each sample, and calculate the cluster center decision factor \(\gamma_{i}\) according to \(\delta_{i}\) and \(\rho_{i}\). Last, we sort the value of \(\gamma_{i}\) in descending order to select the cluster centers as the prototype set.  
```
Input: \(X_{T}^{m\times k}\): data from the target set Output: the prototype \(R^{r\times k}\)
```  
**Algorithm 1**Prototype Selection