-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPlot_maxind_rev1.py
163 lines (104 loc) · 3.9 KB
/
Plot_maxind_rev1.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
import matplotlib.pyplot as plt
import json
import os
import numpy as np
from scipy.optimize import curve_fit
#synthetic
path='/Users/nasimeh/Documents/distributed_GCN-main-6/Oct12_2023/log/maxind_reg_d3_l_rev1_5.log'
with open(path) as f:
Log=f.readlines()
log_d={}
for lines in Log:
temp=lines.split(':')
temp2 = temp[5][1:-9].split(',')
res = [float(tempi[10:-2]) for tempi in temp2]
temp3 = temp[6][1:-7].split(',')
res_th = [float(tempi[10:-2]) for tempi in temp3]
temp4 = temp[8][1:-15].split(',')
time_train = [float(tempi[1:]) for tempi in temp4]
temp5 = temp[9][1:-3].split(',')
time_map = [float(tempi[1:]) for tempi in temp5]
name=temp[2]
total_time=[time_map[i]+time_train[i] for i in range(len(time_map))]
log_d[name]={}
log_d[name]['time']=total_time
log_d[name]['time_train'] = time_train
log_d[name]['time_map'] = time_map
log_d[name]['res'] = res
log_d[name]['res_th'] = res_th
n = int(name[6:-6])
d=3
log_d[name]['n']=n
log_d[name]['d']=d
path='/Users/nasimeh/Documents/distributed_GCN-main-6/Oct12_2023/log/maxind_regular_d3_GNN.log'
with open(path) as f:
Log=f.readlines()
log_r={}
for lines in Log:
temp=lines.split(',')
temp1=temp[1].split(':')
temp2 = temp[2].split(':')
temp3 = temp[3].split(':')
name=temp[0].split(':')[2]
time=float(temp1[1][1:-1])
res = float(temp2[1][11:-4])
res_th = -1*float(temp3[1][10:-4])
log_r[name]={}
log_r[name]['time']=time
log_r[name]['res'] = abs(int(res))
log_r[name]['res_th'] = abs(int(res_th))
x_axis=np.array([log_d[name]['n'] for name in log_d])
y_axis=np.array([np.average(log_d[name]['res'])/log_d[name]['n'] for name in log_d])
y_axis2=np.array([log_r[name]['res_th']/log_d[name]['n'] for name in log_d])
y_axis_error=np.array([np.std(log_d[name]['res'])/log_d[name]['n'] for name in log_d])
# y_axis_=np.array([log_d[name]['res_th']/log_d[name]['n'] for name in log_d])
# y_axis2_=np.array([log_g[name]['res_th']/log_d[name]['n'] for name in log_g])
y_axis_t=np.array([np.average(log_d[name]['time']) for name in log_d])
y_axis_t2=np.array([log_r[name]['time'] for name in log_d])
# y_axis_t3=np.array([log_g[name]['time'] for name in log_g])
nd=len(y_axis)
plotm=np.zeros([10,nd])
plotm[0,:]=x_axis
plotm[1,:]=y_axis
plotm[2,:]=y_axis2
plotm[3,:]=y_axis_t
plotm[4,:]=y_axis_t2
plotm[5,:]=y_axis_error
# plotm[7,:]=y_axis_
# plotm[8,:]=y_axis2_
plotms=plotm[:, plotm[0].argsort()]
y_lower=plotms[1,:]-plotms[5,:]
y_upper=plotms[1,:]+plotms[5,:]
plt.errorbar(plotms[0,:],plotms[1,:], marker='.', label='HypOp')
plt.errorbar(plotms[0,:],plotms[2,:], marker='.', label='PI-GNN')
# plt.errorbar(plotms[0,:],plotms[9,:], yerr = plotms[10,:], label='Bipartite')
plt.fill_between(plotms[0,:], y_lower, y_upper, color='gray', alpha=0.4, label='HypOp Error Region')
plt.ylabel('MIS Size over the Number of Nodes')
plt.xlabel('Number of Nodes')
plt.legend(loc='lower left')
plt.ylim(0.4,0.45)
plt.savefig('./res/plots/Maxind_regular_d3_rev1_5.pdf')
plt.show()
def model_ex(x,a, b):
return b*np.exp(a*x)
def model_l(x,a,b):
return b*(x)+a
popt, pcov = curve_fit(model_ex, plotms[0,:], plotms[4,:], p0=[0,0])
a_r, b_r= popt
x_model = np.linspace(min(plotms[0,:]), max(plotms[0,:]), 100)
y_model = model_ex(x_model, a_r, b_r)
popt, pcov = curve_fit(model_ex, plotms[0,:], plotms[3,:], p0=[0,0])
# popt2, pcov2 = curve_fit(model_l, plotms[0,:], plotms[6,:], p0=[0,0])
a_l, b_l= popt
# a_l2, b_l2= popt2
y_model2 = model_ex(x_model, a_l, b_l)
# y_model3 = model_l(x_model, a_l2, b_l2)
plt.scatter(plotms[0,:], plotms[4,:], label='PI-GNN')
plt.scatter(plotms[0,:], plotms[3,:], color='g', label='HypOp')
plt.plot(x_model, y_model, color='r')
plt.plot(x_model, y_model2, color='y')
plt.ylabel('Run time (s)')
plt.xlabel('Number of Nodes')
plt.legend(loc='upper left')
plt.savefig('./res/plots/Maxind_regular_d3_time_rev1.pdf')
plt.show()