# Can Defect Prediction Be Useful for Coarse-Level Tasks of Software Testing?
## 3 The Association Hierarchy Defect Prediction Method
### Implementation Steps of the Proposed Method  
According to the framework and four phases mentioned in Section 3.2, there are seven steps in total to complete our approach. Details of each step in the framework are illustrated, as follows. In addition, the relationship between phases and steps is represented in Table 1.  
* **Step 1:** determine the goal is making resource allocation for coarse-level tasks and conduct an association hierarchy structure of the ST tasks according to the calling relationship between the outer layer and the inner layer;  
Figure 1: A Framework of The Propose Method.  
**Step 1.1:** apply the first step of AHP to build the hierarchy framework of the ST tasks including three layers (Goal-, Criteria-, and Alternatives-layer) from up to down (Note: Criteria-layer can be divided into one or more sublayers.);
* **Step 1.2:** analyze the relationship between Criteria- or Alternatives-layer, and find the association structure;
* **Step 2:*
* conduct a SDP model (In the paper, we conduct a CPDP model for ranking as paper [38] said.) and predict the defect situation for Alternatives-layer;
* **Step 2.2:*
* use historical defect training data as _Source_ and a defect learner _learner_ to train a SDP model;
* **Step 2.3:*
* apply the _Learner_ to _Target_, which is target project data of Alternatives-layer (i.e., fine-level), to gain the prediction probability vector \(p_{alter}\). The formula is as follows: \[p_{alter}=Learner(Source,Target)=[p_{1},p_{2},\ldots,p_{i},\ldots,p_{q}]^{T}\] (4) where \(p_{i}\) means the prediction probability of the \(i\)th element of Alternatives-layer, \(q\) means the length of this layer;
* **Step 3:** represent the structure of inter- and intro-layers above as directed graphs: \(G_{CA}=(V_{1},E_{1})\), \(G_{CC}=(V_{2},E_{2})\);
* **Step 4:*
* gain incidence matrix \(H_{ca}\)of inter-layers from \(G_{CA}\) and \(H_{cc}\) of intro-layers from \(G_{CC}\).
* **Step 4.1:*
* produce vertical PIM \(H_{ca}\) of inter-layers from graph \(G_{CA}\) (i.e., Criteria-layer and Alternatives-layer), such that \[h_{ca}ij=\begin{cases}1,\text{if the $i$th element of Criteria-layer calls the}\\ \\ 0,\text{else.}\end{cases}\] (5) being \(h_{ca}ij\) the element in the \(i\)th row and \(j\)th column of matrix \(H_{ca}\). Besides, the size of \(H_{ca}\) is \(l\times q\), where \(l\) and \(q\) are the number of elements of Criteria- and Alternatives-layer, respectively;
* **Step 4.2:*
* obtain horizontal PIM \(H_{cc}\) of the Criteria-layer from graph \(G_{CC}\). The formula is as follows: \[h_{cc}ij=\begin{cases}1,\text{if the $i$th element calls the $j$th element of}\\ \\ 0,\text{else.}\end{cases}\] (6) being \(h_{cc}ij\) the element in the \(i\)th row and \(j\)th column of matrix \(H_{ca}\). Moreover, the size of \(H_{cc}\) is \(l\times l\).
* **Step 5:** calculate the prediction probability vector \(p_{cri}\) of Criteria-layer by the following formula: \[p_{cri}=H_{l\times l}\times H_{l\times q}\times p_{alter}=[p_{1},p_{2},\ldots, p_{j},\ldots,p_{l}]^{T}\] (7) where \(p_{j}\) denotes the prediction probability of the \(j\)th element of Criteria-layer, \(l\) means the length of this layer;
* **Step 6:** normalize the prediction probability vector \(p_{cri}\). The formula is illustrated, as follows:\[p_{cri}=\frac{p_{cri}-min(p_{cri})}{max(p_{cri})-min(p_{cri})} \tag{8}\]  
where \(max(p_{cri})\) and \(min(p_{cri})\) are the maximum and minimum value in \(p_{cri}\), respectively.  
* **Step 7:** according to the prediction result to arrange the test resource.