-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_robust.py
115 lines (92 loc) · 4.27 KB
/
test_robust.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
105
106
107
108
109
110
111
112
113
114
115
import pickle
import matplotlib.pyplot as plt
import numpy as np
epsilons = np.linspace(0, 0.2, num=10)
test_robust_file_4 = 'adversarial/test_robust_exp4.pickle'
test_robust_file_5 = 'adversarial/test_robust_exp5.pickle'
test_robust_file_6 = 'adversarial/test_robust_exp6.pickle'
# test_robust_file = 'adversarial/test_robust_exp3.pickle'
# test_robust_acc = pickle.load(open(test_robust_file, 'rb'))
test_robust_acc_4 = pickle.load(open(test_robust_file_4, 'rb'))
test_robust_acc_5 = pickle.load(open(test_robust_file_5, 'rb'))
test_robust_acc_6 = pickle.load(open(test_robust_file_6, 'rb'))
"""
for model_class, robust_acc in test_robust_acc.items():
# if model_class == 'lambda_vary' or model_class == 'lambda_equal':
plt.plot(epsilons, robust_acc, label=model_class)
plt.legend()
plt.show()
exit()
"""
robust_acc_vary = []
robust_acc_equal = []
robust_acc_normal = []
robust_acc_blackout = []
for model_class, robust_acc in test_robust_acc_4.items():
if model_class == 'lambda_vary':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_vary.append(robust_acc)
elif model_class == 'lambda_equal':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_equal.append(robust_acc)
elif model_class == 'normal':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_normal.append(robust_acc)
elif model_class == 'blackout':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_blackout.append(robust_acc)
else:
continue
for model_class, robust_acc in test_robust_acc_5.items():
if model_class == 'lambda_vary':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_vary.append(robust_acc)
elif model_class == 'lambda_equal':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_equal.append(robust_acc)
elif model_class == 'normal':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_normal.append(robust_acc)
elif model_class == 'blackout':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_blackout.append(robust_acc)
else:
continue
for model_class, robust_acc in test_robust_acc_6.items():
if model_class == 'lambda_vary':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_vary.append(robust_acc)
elif model_class == 'lambda_equal':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_equal.append(robust_acc)
elif model_class == 'normal':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_normal.append(robust_acc)
elif model_class == 'blackout':
# robust_acc = np.array([v for i, v in enumerate(robust_acc) if i % 2 == 0])
robust_acc_blackout.append(robust_acc)
else:
continue
robust_acc_vary = np.vstack(robust_acc_vary)
robust_acc_equal = np.vstack(robust_acc_equal)
robust_acc_normal = np.vstack(robust_acc_normal)
robust_acc_blackout = np.vstack(robust_acc_blackout)
vary_mean = np.mean(robust_acc_vary, axis=0)
vary_std = np.std(robust_acc_vary, axis=0)
equal_mean = np.mean(robust_acc_equal, axis=0)
equal_std = np.std(robust_acc_equal, axis=0)
normal_mean = np.mean(robust_acc_normal, axis=0)
normal_std = np.std(robust_acc_normal, axis=0)
blackout_mean = np.mean(robust_acc_blackout, axis=0)
blackout_std = np.std(robust_acc_blackout, axis=0)
fig, ax = plt.subplots()
ax.plot(epsilons, vary_mean, label='lambda vary')
ax.fill_between(epsilons, (vary_mean - vary_std), (vary_mean + vary_std), alpha=0.3)
ax.plot(epsilons, equal_mean, label='lambda equal')
ax.fill_between(epsilons, (equal_mean - equal_std), (equal_mean + equal_std), alpha=0.3)
ax.plot(epsilons, normal_mean, label='normal')
ax.fill_between(epsilons, (normal_mean - normal_std), (normal_mean + normal_std), alpha=0.3)
ax.plot(epsilons, blackout_mean, label='blackout')
ax.fill_between(epsilons, (blackout_mean - blackout_std), (blackout_mean + blackout_std), alpha=0.3)
plt.legend()
plt.show()