-
Notifications
You must be signed in to change notification settings - Fork 6
/
RQ2_3.py
104 lines (83 loc) · 4 KB
/
RQ2_3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
"""
Compare BELLTREE with other threshold based learners.
"""
from __future__ import print_function, division
import os
import sys
# Update path
root = os.path.join(os.getcwd().split('src')[0], 'src')
if root not in sys.path:
sys.path.append(root)
from planners.XTREE import xtree
from planners.alves import alves
from utils.plot_util import plot_bar
from planners.shatnawi import shatnawi
from planners.oliveira import oliveira
from data.get_data import get_all_projects
from utils.file_util import list2dataframe
from utils.stats_utils.auec import compute_auec
from utils.rq_utils import measure_overlap, reshape
def research_question_2_3(decrease=True, verbose=True, plot_results=True):
"""
RQ2: How effective is BELLTREE?
RQ3: How does XTREE compare with BELLTREE? (The BELLTREE part of this RQ is answered here)
Parameters
----------
decrease: Bool
Compute AUPEC for defects reduced.
verbose: Bool
Display results on the console
plot_results: Bool
Plot barcharts of overlap vs. defects reduced/increased
"""
data = get_all_projects()
bellw = data.pop('lucene').data
train = list2dataframe(bellw)
if verbose:
print("Data \tXTREE\tAlves\tShatw\tOlive")
for proj, paths in data.items():
i = 0
for test, validation in zip(paths.data[1:-1], paths.data[2:]):
i += 1
"Convert to pandas type dataframe"
test = list2dataframe(test)
validation = list2dataframe(validation)
"Recommend changes with XTREE"
patched_xtree = xtree(train[train.columns[1:]], test)
patched_alves = alves(train[train.columns[1:]], test)
patched_shatw = shatnawi(train[train.columns[1:]], test)
patched_olive = oliveira(train[train.columns[1:]], test)
res_xtree = measure_overlap(test, patched_xtree, validation)
res_alves = measure_overlap(test, patched_alves, validation)
res_shatw = measure_overlap(test, patched_shatw, validation)
res_olive = measure_overlap(test, patched_olive, validation)
res_dec, res_inc = reshape(res_xtree, res_alves, res_shatw, res_olive)
"Plot the results"
if plot_results:
plot_bar(res_inc, res_dec, save_path=os.path.join(
root, "results", "RQ1", proj), title="{} v{}".format(proj, i), y_lbl="Defects",
postfix="")
"Max/Min to normalize AUPEC"
y_max = max(res_dec.max(axis=0).values)
y_min = max(res_dec.min(axis=0).values)
if decrease:
"Decrease AUC"
xtree_dec_auc = compute_auec(res_dec[["Overlap", "XTREE"]], y_max, y_min)
alves_dec_auc = compute_auec(res_dec[["Overlap", "Alves"]], y_max, y_min)
shatw_dec_auc = compute_auec(res_dec[["Overlap", "Shatnawi"]], y_max, y_min)
olive_dec_auc = compute_auec(res_dec[["Overlap", "Oliveira"]], y_max, y_min)
if verbose:
print("{}-{}\t{}\t{}\t{}\t{}".format(proj[:3], i, xtree_dec_auc, alves_dec_auc, shatw_dec_auc, olive_dec_auc))
else:
"Increase AUC"
xtree_inc_auc = compute_auec(res_inc[["Overlap", "XTREE"]], y_max, y_min)
alves_inc_auc = compute_auec(res_inc[["Overlap", "Alves"]], y_max, y_min)
shatw_inc_auc = compute_auec(res_inc[["Overlap", "Shatnawi"]], y_max, y_min)
olive_inc_auc = compute_auec(res_inc[["Overlap", "Oliveira"]], y_max, y_min)
if verbose:
print("{}-{}\t{}\t{}\t{}\t{}".format(proj[:3], i, xtree_inc_auc, alves_inc_auc, shatw_inc_auc, olive_inc_auc))
if __name__ == "__main__":
print("AUPEC: Defects Reduced\n{}".format(22*"-"))
research_question_2_3(decrease=True, verbose=True, plot_results=False)
print("\n"+40*"="+"\nAUPEC: Defects Increased\n"+24*"-")
research_question_2_3(decrease=False, verbose=True, plot_results=False)