Skip to content

Commit

Permalink
refact: beautify venn graphs
Browse files Browse the repository at this point in the history
  • Loading branch information
ganler committed Jun 17, 2022
1 parent b9bb1bf commit d0d8ef8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 32 deletions.
27 changes: 20 additions & 7 deletions experiments/plot_inp_search_merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
parser = argparse.ArgumentParser()
parser.add_argument('--root', type=str, nargs='+', required=True)
parser.add_argument('--output', type=str, default='results')
parser.add_argument('--rm_slowest', action='store_true',
help='Remove the slowest run')
args = parser.parse_args()

REGEX_PATTERN = '(\d+)-model-(\d+)-node-exp'
Expand Down Expand Up @@ -65,15 +67,17 @@ def sort_by_time(time, succ_rate):

# Do not count the slowest iteration (1st iter usually)
# as initialization takes some time.
idx = data['sampling-time'].to_numpy().argsort()[:-2]
last_idx = -2 if args.rm_slowest else -1

idx = data['sampling-time'].to_numpy().argsort()[:last_idx]
sampling_time.append(data['sampling-time'][idx].mean())
sampling_succ_rate.append(data['sampling-succ'][idx].mean())

idx = data['grad-time'].to_numpy().argsort()[:-2]
idx = data['grad-time'].to_numpy().argsort()[:last_idx]
grad_time.append(data['grad-time'][idx].mean())
grad_succ_rate.append(data['grad-succ'][idx].mean())

idx = data['proxy-time'].to_numpy().argsort()[:-2]
idx = data['proxy-time'].to_numpy().argsort()[:last_idx]
proxy_time.append(data['proxy-time'][idx].mean())
proxy_succ_rate.append(data['proxy-succ'][idx].mean())
elif f == 'model_info.csv':
Expand All @@ -95,6 +99,8 @@ def sort_by_time(time, succ_rate):
markeredgewidth = 1.2
lw = 1.5

max_time = 0

for i in range(3):
c = colors[i]
alpha = 1 - 0.36 * i
Expand All @@ -103,16 +109,23 @@ def sort_by_time(time, succ_rate):
grad_time, grad_succ_rate = grad_res[i]
proxy_time, proxy_succ_rate = proxy_res[i]

ax.plot(proxy_time * 1000, proxy_succ_rate, marker=markers[0],
# self *= 1000: sec -> milli
sampling_time *= 1000
grad_time *= 1000
proxy_time *= 1000

ax.plot(proxy_time, proxy_succ_rate, marker=markers[0],
markeredgecolor=markercolor, markersize=markersize, markeredgewidth=markeredgewidth,
linestyle=':', color=c, lw=lw)
ax.plot(grad_time * 1000, grad_succ_rate, marker=markers[1],
ax.plot(grad_time, grad_succ_rate, marker=markers[1],
markeredgecolor=markercolor, markersize=markersize, markeredgewidth=markeredgewidth,
linestyle=':', color=c, lw=lw)
ax.plot(sampling_time * 1000, sampling_succ_rate, marker=markers[2],
ax.plot(sampling_time, sampling_succ_rate, marker=markers[2],
markeredgecolor=markercolor, markersize=markersize, markeredgewidth=markeredgewidth,
linestyle=':', color=c, lw=lw)

max_time = max(max_time, sampling_time.max())

ax.grid(True, linestyle=':', linewidth=.5, alpha=0.5)

lines = ax.get_lines()
Expand All @@ -133,7 +146,7 @@ def sort_by_time(time, succ_rate):
ax.set_ylim(0.6, 1.0)

ax.set_xticks(np.arange(0, 31, 5))
ax.set_xlim(0, 35)
ax.set_xlim(0, max_time + 0.5)

ax.set_xlabel('Avg. Searching Time (millisecond)', fontweight='bold')
ax.set_ylabel('Success Rate', fontweight='bold')
Expand Down
53 changes: 28 additions & 25 deletions experiments/viz_merged_cov.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import matplotlib.pyplot as plt
from matplotlib_venn import venn2, venn3
from matplotlib_venn import venn2, venn3, _venn3
import numpy as np

import os
Expand Down Expand Up @@ -263,37 +263,40 @@ def plot_one_round(folder, data, pass_filter=None, fuzz_tags=None, target_tag=''
v = venn2(subsets=branch_cov_sets, set_labels=[
f'$\\bf{{{t}}}$' for t in fuzz_tags], alpha=0.3)
elif len(branch_cov_sets) == 3:
v = venn3(subsets=branch_cov_sets, set_labels=[
f'$\\bf{{{t}}}$' for t in fuzz_tags], alpha=0.3)
ks = ['100', '010', '110', '001', '101', '011', '111']
sets = {}
for k, val in zip(ks, _venn3.compute_venn3_subsets(*branch_cov_sets)):
sets[k] = val
v = venn3(subsets=(7, 7, 3, 7, 3, 3, 5), set_labels=[
f'{t}' for t in fuzz_tags])

for id in ['110', '101', '011']:
if v.get_label_by_id(id):
v.get_label_by_id(id).set_text('')

# v.get_label_by_id("100").set_x(v.get_label_by_id('100').get_position()[0] * 1.05)
# v.get_label_by_id("010").set_x(v.get_label_by_id('010').get_position()[0] * 1.3)
# v.get_label_by_id("001").set_x(v.get_label_by_id('001').get_position()[0] * 1.2)

h, l = [], []
hatches = ['\\', '.', '*']
circles = ['MediumVioletRed', 'SeaGreen', 'Lavender']
v.get_label_by_id(id).set_text(sets[id])
v.get_patch_by_id(id).set_alpha(0.15)
v.get_label_by_id(id).set_fontsize(MEDIUM_SIZE)

hatches = ['*', '.', '\\']
# circles = ['dodgerblue', 'MediumVioletRed', 'coral', 'white'] # colorful.
circles = ['k'] * 4 # chill man!
fcolors = ['lightblue', 'violet', 'navajowhite']
for idx, id in enumerate(['100', '010', '001', '111']):
if v.get_label_by_id(id) is None:
if sets[id] == 0:
continue
cnt = int(v.get_label_by_id(id).get_text())
v.get_label_by_id(id).set_text('')
cnt = sets[id]
v.get_label_by_id(id).set_text(f'\\textbf{{{cnt}}}')
v.get_label_by_id(id).set_fontsize(BIGGER_SIZE + 4)
v.get_patch_by_id(id).set_edgecolor(circles[idx])
if id != '111':
v.get_patch_by_id(id).set_alpha(0.5)
v.get_patch_by_id(id).set_hatch(hatches[idx])
v.get_patch_by_id(id).set_edgecolor(circles[idx])
v.get_patch_by_id(id).set_linewidth(2)
# append patch to handles list
h.append(v.get_patch_by_id(id))
# append count to labels list
l.append(cnt)

plt.legend(handles=h, labels=l, title="counts", loc='lower right')
plt.title("Venn Diagram of Branch Coverage")
v.get_patch_by_id(id).set_facecolor(fcolors[idx])
# v.get_patch_by_id(id).set_linewidth(2)
else:
v.get_patch_by_id(id).set_alpha(0.2)

for text in v.set_labels:
text.set_fontsize(BIGGER_SIZE)

plt.savefig(f'{os.path.join(folder, target_tag + pass_tag + "br_cov_venn")}.png',
bbox_inches='tight')
if pdf:
Expand Down

0 comments on commit d0d8ef8

Please sign in to comment.