-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathplot_variation.py
46 lines (39 loc) · 1.2 KB
/
plot_variation.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
import numpy as np
import matplotlib.pyplot as plt
from efficiency.log import show_var
file = 'nodes_vs_variations.txt'
import csv
with open(file) as f:
reader = csv.DictReader(f, delimiter=' ')
content = list(reader)
node_num_n_var = [(int(i['#nodes']), int(i['#diffs'])) for i in content]
from collections import Counter
counter = Counter(node_num_n_var)
print(counter.most_common())
counter = dict(sorted(counter.items()))
x, y = zip(*counter.keys())
cnt = counter.values()
radius = np.array(list(cnt)) / 2
area = radius ** 2 * np.pi
# Fixing random state for reproducibility
np.random.seed(19680801)
colors = np.random.rand(len(counter))
plt.scatter(x, y, s=area, c=colors, alpha=0.5)
plt.xlabel('# Triples of the Input Graph in WebNLG 2017')
plt.ylabel('# Variations of Generated Text')
plt.title("Text Diversity Generated by CycleCVAE")
x2argmax_y = {}
for (x, y), cnt in counter.items():
if cnt < 10:
continue
if x in x2argmax_y:
prev_y, prev_cnt = x2argmax_y[x]
if cnt < prev_cnt:
continue
x2argmax_y[x] = (y, cnt)
x = list(x2argmax_y.keys())
y, cnt =zip(*x2argmax_y.values())
show_var(['x', 'y'])
import pdb;pdb.set_trace()
plt.plot(x, y)
plt.show()