-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_tree_sens.py
182 lines (155 loc) · 5.23 KB
/
plot_tree_sens.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import matplotlib.pylab as plt
import pickle
import numpy as np
import copy
style = ['-.', '-', '--', ':']
x_layer = [[0], [1], [2,3,4], [5,6,7,8,9,10,11,12,13]]
z_layer = [[(0,1)], [(1,2), (1,3), (1,4)], [(2,5), (2,6), (2,7), (3,8), (3,9), (3,10), (4,11), (4,12), (4,13)]]
def lineplot(filename, x_ax, y_ax, xaxis_label, yaxis_label):
P = len(y_ax) #number of plot
A = len(y_ax[0]) # number of algorithm
S = len(y_ax[0][0]) # number of parameter
fig, ax = plt.subplots(nrows=P, ncols=1)
fig.set_size_inches(5,P*2)
for i in range(P):
title = 'layer '+str(i)
ax[i].set_title(title, fontsize=10)
for j in [2,1,0]:
# ax[i].set_yscale('log')
ax[i].plot(x_ax, y_ax[i][j], style[j], linewidth=2)
ax[i].set_ylabel('Cost', fontsize=10)
ax[i].tick_params(labelsize=10)
plt.xlabel(xaxis_label, fontsize=10)
plt.subplots_adjust(hspace=0.4)
lgd = plt.legend(labels=yaxis_label, fontsize=10, loc='upper center', bbox_to_anchor=(0.5, 4.3), ncol=A,)
plt.show()
fig.savefig('figure/'+filename+'.pdf', bbox_extra_artists=(lgd,), bbox_inches = 'tight')
def lineplot2(filename, x_ax, y_ax1, y_ax2, xaxis_label, yaxis_label):
P = len(y_ax1) #number of plot
A = len(y_ax1[0]) # number of algorithm
S = len(y_ax1[0][0]) # number of parameter
fig, ax = plt.subplots(nrows=P, ncols=2)
fig.set_size_inches(7,P*3)
for i in range(P):
title = 'layer '+str(i)
ax[i, 0].set_title(title, fontsize=10)
ax[i, 1].set_title(title, fontsize=10)
for j in [2,1,0]:
# ax[i].set_yscale('log')
ax[i,0].plot(x_ax, y_ax1[i][j], style[j], linewidth=2)
ax[i,0].set_ylabel('Cost', fontsize=10)
ax[i,0].tick_params(labelsize=10)
ax[i,1].plot(x_ax, y_ax2[i][j], style[j], linewidth=2)
ax[i,1].set_ylabel('Load', fontsize=10)
ax[i,1].tick_params(labelsize=10)
if i == P-1:
ax[i,0].set_xlabel(xaxis_label, fontsize=10)
ax[i,1].set_xlabel(xaxis_label, fontsize=10)
plt.subplots_adjust(hspace=0.3)
plt.subplots_adjust(wspace=0.3)
lgd = plt.legend(labels=yaxis_label, fontsize=10, loc='upper center', bbox_to_anchor=(-0.2, 3.9), ncol=A,)
plt.show()
fig.savefig('figure/'+filename+'.pdf', bbox_extra_artists=(lgd,), bbox_inches = 'tight')
filename = 'penalty_all'
scale = [1.0, 1.2, 1.4, 1.6, 1.8, 2.0]
y_ax = []
for mul in scale:
y = []
fname = 'tree_penalty_asymmetric/tree_up_' + str(mul)
with open(fname, 'rb') as f:
[x, z, objE, objV] = pickle.load(f)
z_group = []
for e_group in z_layer:
objE = 0
for e in e_group:
ze = 0
for ii in z[e]:
ze += z[e][ii]
objE += pow(ze, mul)
if objE < 0:
objE = 0
z_group.append(objE)
y.append(z_group)
fname = 'tree_penalty_asymmetric/tree_up_ma_' + str(mul)
with open(fname, 'rb') as f:
[x, z, objE, objV] = pickle.load(f)
z_group = []
for e_group in z_layer:
objE = 0
for e in e_group:
ze = 0
for ii in z[e]:
ze += z[e][ii]
objE += pow(ze, mul)
if objE < 0:
objE = 0
z_group.append(objE)
y.append(z_group)
fname = 'tree_penalty_asymmetric/tree_up_nocc_' + str(mul)
with open(fname, 'rb') as f:
[x, z, objE, objV] = pickle.load(f)
z_group = []
for e_group in z_layer:
objE = 0
for e in e_group:
ze = 0
for ii in z[e]:
ze += z[e][ii]
objE += pow(ze, mul)
if objE < 0:
objE = 0
z_group.append(objE)
y.append(z_group)
y_ax.append(y)
y_ax1 = np.array(y_ax).transpose()
y_ax = []
for mul in scale:
y = []
fname = 'tree_penalty_asymmetric/tree_up_' + str(mul)
with open(fname, 'rb') as f:
[x, z, objE, objV] = pickle.load(f)
z_group = []
for e_group in z_layer:
objE = 0
for e in e_group:
ze = 0
for ii in z[e]:
ze += z[e][ii]
objE += pow(ze, 1)
if objE < 0:
objE = 0
z_group.append(objE)
y.append(z_group)
fname = 'tree_penalty_asymmetric/tree_up_ma_' + str(mul)
with open(fname, 'rb') as f:
[x, z, objE, objV] = pickle.load(f)
z_group = []
for e_group in z_layer:
objE = 0
for e in e_group:
ze = 0
for ii in z[e]:
ze += z[e][ii]
objE += pow(ze, 1)
if objE < 0:
objE = 0
z_group.append(objE)
y.append(z_group)
fname = 'tree_penalty_asymmetric/tree_up_nocc_' + str(mul)
with open(fname, 'rb') as f:
[x, z, objE, objV] = pickle.load(f)
z_group = []
for e_group in z_layer:
objE = 0
for e in e_group:
ze = 0
for ii in z[e]:
ze += z[e][ii]
objE += pow(ze, 1)
if objE < 0:
objE = 0
z_group.append(objE)
y.append(z_group)
y_ax.append(y)
y_ax2 = np.array(y_ax).transpose()
lineplot2(filename, scale, y_ax1, y_ax2, 'Penalty Multiplier', ['No Cross Coding', 'Maddah-Ali','Coded Cache'])