Skip to content

Commit

Permalink
Autocommit
Browse files Browse the repository at this point in the history
  • Loading branch information
rahlk committed Mar 10, 2019
1 parent e7ca4d1 commit de7af25
Show file tree
Hide file tree
Showing 35 changed files with 4,334 additions and 222 deletions.
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ tabulate
scipy
numpy
matplotlib
seaborn
statsmodels
155 changes: 92 additions & 63 deletions src/experiments/experiment1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
from planners.shatnawi import shatnawi
from planners.oliveira import oliveira
from utils.rq_utils import measure_overlap, reshape
from utils.plot_util import plot_bar, plot_compare
from utils.plot_util_clean import plot_violin, plot_catplot
from utils.stats_utils.auec import compute_auec
from utils.rq_utils import measure_overlap, reshape

from sklearn.model_selection import train_test_split

class Experiment1:
def __init__(self, plot_results=False, decrease=True, verbose=True):
def __init__(self, plot_results=True, decrease=True, verbose=True):
self.plot_results = plot_results
self.decrease = decrease
self.verbose = verbose
Expand All @@ -35,76 +35,105 @@ def main(self):
i = 0
for train, test, validation in zip(paths.data[:-2], paths.data[1:-1], paths.data[2:]):
i += 1
# -- Save names and save paths
plot_title = "{} v{}".format(proj, i)
save_path = os.path.join(root, "results", "RQ1", proj)
if self.verbose:
print(plot_title)
# -- Create dataframes to hold the results --
columns = ["Overlap", "Num", "Method"]
decrease = pd.DataFrame(columns = columns)
increase = pd.DataFrame(columns = columns)

# -- Create a dataframe for train and test --
test_df = pd.read_csv(test)
test_df_full = pd.read_csv(test)
train_df = pd.read_csv(train)
valdn_df = pd.read_csv(validation)

# -- Binarize training data labels --
train_df.loc[train_df[train_df.columns[-1]]
> 0, train_df.columns[-1]] = 1

# -- Build an XTREE Model --
xtree = XTREE()
xtree = xtree.fit(train_df)

# -- Generate Plans --
patched_xtree = xtree.predict(test_df)
patched_alves = alves(train_df[train_df.columns[1:]], test)
patched_shatw = shatnawi(train_df[train_df.columns[1:]], test)
patched_olive = oliveira(train_df[train_df.columns[1:]], test)

# -- Compute overlap with developers changes --
res_xtree = measure_overlap(test_df, patched_xtree, valdn_df)
res_alves = measure_overlap(test_df, patched_alves, valdn_df)
res_shatw = measure_overlap(test_df, patched_shatw, valdn_df)
res_olive = measure_overlap(test_df, patched_olive, valdn_df)

# -- Summary of defects decreased/increased --
res_dec, res_inc = reshape(
res_xtree, res_alves, res_shatw, res_olive)

# --------------------------------------------------------------
# -- Repeat 10 times with 90% samples --
for repeats in range(30):
# -- Split the test data --
test_df, __ = train_test_split(test_df_full, test_size=0.1, random_state=1729)

# -- Build an XTREE Model --
xtree_arplan = XTREE(strategy="itemset")
xtree_arplan = xtree_arplan.fit(train_df)

# -- Generate Plans --
patched_xtree = xtree_arplan.predict(test_df)
patched_alves = alves(train_df[train_df.columns[1:]], test)
patched_shatw = shatnawi(train_df[train_df.columns[1:]], test)
patched_olive = oliveira(train_df[train_df.columns[1:]], test)

# -- Compute overlap with developers changes --
res_xtree = measure_overlap(test_df, patched_xtree, valdn_df)
res_alves = measure_overlap(test_df, patched_alves, valdn_df)
res_shatw = measure_overlap(test_df, patched_shatw, valdn_df)
res_olive = measure_overlap(test_df, patched_olive, valdn_df)

# -- Summary of defects decreased/increased --
res_dec, res_inc = reshape(res_xtree, res_alves, res_shatw, res_olive)

decrease = decrease.append(res_dec, ignore_index=True)
increase = increase.append(res_inc, ignore_index=True)

decrease.to_csv(os.path.join(save_path, plot_title+"_dec.csv"), index=False)
increase.to_csv(os.path.join(save_path, plot_title+"_inc.csv"), index=False)

# --------------------------------------------------------------
# -- Plot the results --
if self.plot_results:
plot_compare(res_dec, save_path=os.path.join(root, "results", "RQ1", proj), title="{} v{}".format(
proj, i), y_lbl="# Defects Removed", postfix="dec")

plot_compare(res_inc, save_path=os.path.join(root, "results", "RQ1", proj), title="{} v{}".format(
proj, i), y_lbl="# Defects Added", postfix="inc")

# -- Max/Min to normalize AUPEC --
y_max = max(res_dec.max(axis=0).values)
y_min = min(res_dec.min(axis=0).values)

if self.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 self.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 self.verbose:
print("{}-{}\t{}\t{}\t{}\t{}".format(
proj[:3], i, xtree_inc_auc, alves_inc_auc, shatw_inc_auc, olive_inc_auc))
# --- Violin plots ---

# -- Decreased --
plot_catplot(decrease, save_path=save_path, title=plot_title,
y_lbl="# Defects Removed", postfix="dec")
# -- Increased --
plot_catplot(increase, save_path=save_path, title=plot_title,
y_lbl="# Defects Added", postfix="inc")


# -- Pause execution --
# set_trace()

# # -- Max/Min to normalize AUPEC --
# y_max = max(res_dec.max(axis=0).values)
# y_min = min(res_dec.min(axis=0).values)

# if self.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 self.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 self.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__":
Expand Down
Loading

0 comments on commit de7af25

Please sign in to comment.