-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathplot.py
125 lines (94 loc) · 4.64 KB
/
plot.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
116
117
118
119
120
121
122
123
124
125
'''
Plots 10 independent trials of each algorithm and saves to a file './result/plot_dec.png'
'''
import numpy as np
import pickle
import matplotlib.pyplot as plt
dgd_b0 = []
dgd_b2 = []
byrdie_b2_faultless = []
byrdie_b2 = []
bridge_b2_faultless = []
bridge_b2 = []
median_b2_faultless = []
median_b2 = []
krum_b2_faultless = []
krum_b2 = []
bulyan_b2_faultless = []
bulyan_b2 = []
krum_b4_faultless = []
krum_b4 = []
krum_b3_faultless = []
krum_b3 = []
for monte in range(10):
with open(f'./result/DGD/result_20_nodes_50%_b0_faultless_{monte}.pickle', 'rb') as handle:
dgd_b0.append(pickle.load(handle))
with open(f'./result/DGD/result_20_nodes_50%_b2_{monte}.pickle', 'rb') as handle:
dgd_b2.append(pickle.load(handle))
with open(f'./result/ByRDiE/result_20_nodes_50%_b0_faultless_{monte}.pickle', 'rb') as handle:
byrdie_b2_faultless.append(pickle.load(handle))
with open(f'./result/ByRDiE/result_20_nodes_50%_b2_{monte}.pickle', 'rb') as handle:
byrdie_b2.append(pickle.load(handle))
with open(f'./result/BRIDGE/result_20_nodes_50%_b2_faultless_{monte}.pickle','rb') as handle:
bridge_b2_faultless.append(pickle.load(handle))
with open(f'./result/BRIDGE/result_20_nodes_50%_b2_{monte}.pickle','rb') as handle:
bridge_b2.append(pickle.load(handle))
with open(f'./result/Median/result_20_nodes_50%_b2_faultless_{monte}.pickle','rb') as handle:
median_b2_faultless.append(pickle.load(handle))
with open(f'./result/Median/result_20_nodes_50%_b2_{monte}.pickle','rb') as handle:
median_b2.append(pickle.load(handle))
with open(f'./result/Krum/result_20_nodes_50%_b2_faultless_{monte}.pickle','rb') as handle:
krum_b2_faultless.append(pickle.load(handle))
with open(f'./result/Krum/result_20_nodes_50%_b2_{monte}.pickle','rb') as handle:
krum_b2.append(pickle.load(handle))
with open(f'./result/Bulyan/result_20_nodes_50%_b2_faultless_{monte}.pickle','rb') as handle:
bulyan_b2.append(pickle.load(handle))
with open(f'./result/Bulyan/result_20_nodes_50%_b2_{monte}.pickle','rb') as handle:
bulyan_b2_faultless.append(pickle.load(handle))
smooth_dgd_b0 = np.mean(dgd_b0, axis=0)
smooth_dgd_b2 = np.mean(dgd_b2, axis=0)
smooth_byrdie_b2_faultless = np.mean(byrdie_b2_faultless, axis=0)
smooth_byrdie_b2 = np.mean(byrdie_b2, axis=0)
smooth_byrdie_b2_FL = np.mean(smooth_byrdie_b2_faultless, axis=1)
smooth_byrdie_b2 = np.mean(smooth_byrdie_b2, axis=1)
smooth_bridge_b2_faultless = np.mean(bridge_b2_faultless, axis=0)
smooth_bridge_b2 = np.mean(bridge_b2, axis=0)
smooth_median_b2_faultless = np.mean(median_b2_faultless, axis=0)
smooth_median_b2 = np.mean(median_b2, axis=0)
smooth_krum_b2_faultless = np.mean(krum_b2_faultless, axis=0)
smooth_krum_b2 = np.mean(krum_b2, axis=0)
smooth_bulyan_b2_faultless = np.mean(bulyan_b2, axis=0)
smooth_bulyan_b2 = np.mean(bulyan_b2, axis=0)
scalar_comms = [7840*n for n in range(100)]
byrdie_axis = []
for t in range(100):
for p in range(39):
byrdie_axis.append(t * 7840 + (p+1) * 200)
for p in range(10, 11):
byrdie_axis.append((t+1) * 7840 + p)
plot_faultless = plt.figure(figsize=(15,6))
plt.subplot(1,2,1)
plt.plot(scalar_comms, smooth_dgd_b0*100, markevery=5, marker='v')
plt.plot(byrdie_axis[:3960], smooth_byrdie_b2_FL[:3960]*100, markevery=200, marker='.')
plt.plot(scalar_comms, smooth_bridge_b2_faultless*100, markevery=5, marker='p', color='g')
plt.plot(scalar_comms, smooth_median_b2_faultless*100, markevery=5, marker='s', color='r')
plt.plot(scalar_comms, smooth_krum_b2_faultless*100, markevery=5, marker='s', color='m')
plt.plot(scalar_comms, smooth_bulyan_b2_faultless*100, markevery=5, marker='x')
plt.ylim((5,90))
plt.ylabel('Average classification accuracy (%)')
plt.xlabel('Number of scalar Broadcasts per node')
plt.title('Faultless setting')
plt.legend(['DGD','ByRDiE','BRIDGE','Median','Krum','Bulyan'], loc='right')
plt.subplot(1,2,2)
plt.plot(scalar_comms, smooth_dgd_b2*100, markevery=5, marker='v')
plt.plot(byrdie_axis[:3960], smooth_byrdie_b2[:3960]*100, markevery=200, marker='.')
plt.plot(scalar_comms, smooth_bridge_b2*100, markevery=5, marker='p', color='g')
plt.plot(scalar_comms, smooth_median_b2*100, markevery=5, marker='s', color='r')
plt.plot(scalar_comms, smooth_krum_b2*100, markevery=5, marker='s', color='m')
plt.plot(scalar_comms, smooth_bulyan_b2*100, markevery=5, marker='x')
plt.ylim((5,90))
plt.ylabel('Average classification accuracy (%)')
plt.xlabel('Number of scalar Broadcasts per node')
plt.title('Faulty setting')
plt.legend(['DGD','ByRDiE','BRIDGE','Median','Krum','Bulyan'], loc='right')
plt.savefig('./result/plot_dec.png', bboxinches='tight')