-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakeComparisonPlot.py
More file actions
175 lines (136 loc) · 5.28 KB
/
MakeComparisonPlot.py
File metadata and controls
175 lines (136 loc) · 5.28 KB
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
import os
import sys
import time
import pandas as pd
import matplotlib.pyplot as plt
dirname = os.path.dirname
sys.path.append(dirname(dirname(os.path.realpath(__file__))))
def skip_rows_err (index):
if index <10 or index > 10:
return True
return False
def skip_rows_seen (index):
if index <13 or index > 13:
return True
return False
def valid_file (data_dir,file):
path = os.path.join(data_dir, file)
if os.path.isdir(path):
# skip directories
return False
if file.startswith('.'):
return False
return True
def parse_outfile (data_file):
df_median_error = pd.read_csv(data_file, sep=",",skiprows=lambda x: skip_rows_err(x),header=None, usecols=[1])
median_error = df_median_error.iloc[0,0]
df_edges_seen = pd.read_csv(data_file, sep=",",skiprows=lambda x: skip_rows_seen(x),header=None, usecols=[0])
edges_seen = df_edges_seen.iloc[0,0]
df_edges_seen = pd.read_csv(data_file, sep=",",skiprows=lambda x: skip_rows_seen(x),header=None, usecols=[1])
vertices_seen = df_edges_seen.iloc[0,0]
return median_error,edges_seen, vertices_seen
def populate_data (data_dir):
X = []
Y=[]
Z=[]
for i, file in enumerate(os.listdir(data_dir)):
data_file = data_dir + file
if valid_file(data_dir,file):
median_error, edges_seen, vertices_seen = parse_outfile(data_file)
Y.append(median_error)
X.append(edges_seen)
Z.append(vertices_seen)
return X,Y,Z
def make_plot_edge (X,Y,filename, title_info, save):
#scatter plot
fig, ax_edge = plt.subplots()
ax_edge.plot(X[1], Y[1], c='red', marker='o', label='SEC',markersize=12)
ax_edge.plot(X[2], Y[2], c='red', marker='^', label='SERWC',markersize=12)
ax_edge.plot(X[3], Y[3], c='red', marker='D', label='UESS',markersize=12)
ax_edge.plot(X[0], Y[0], c='blue', marker='s', label='TETRIS',markersize=12)
#ax_edge.set_xlim(0.15,1.1)
ax_edge.set_ylim(0,20)
ax_edge.legend(loc='upper right',fontsize=18)
#add x and y labels
ax_edge.set_xlabel('Percentage of Edges Visited',fontsize=20)
ax_edge.set_ylabel('Median Relative Error %' ,fontsize=20)
ax_edge.tick_params(axis="y", labelsize=18)
ax_edge.tick_params(axis="x", labelsize=18)
#add title
fig.suptitle(title_info,fontsize=18)
#show plot
plt.show()
timestr = time.strftime("%Y%m%d-%H%M%S")
if (save):
fig.savefig("output/plots/comparison/"+filename+timestr+".eps",format='eps',bbox_inches="tight")
def make_plot_vertex(Z,Y,filename, title_info, save):
#scatter plot
fig, ax_vertex = plt.subplots()
ax_vertex.plot(Z[1], Y[1], c='red', marker='o', label='SEC',markersize=12)
ax_vertex.plot(Z[2], Y[2], c='red', marker='^', label='SERWC',markersize=12)
ax_vertex.plot(Z[3], Y[3], c='red', marker='D', label='UESS',markersize=12)
ax_vertex.plot(Z[0], Y[0], c='blue', marker='s', label='TETRIS',markersize=12)
ax_vertex.set_xlim(1,8)
ax_vertex.set_ylim(0,15)
ax_vertex.legend(loc='upper right',fontsize=18)
#add x and y labels
ax_vertex.set_xlabel('Percentage of Vertices Visited',fontsize=20)
ax_vertex.set_ylabel('Median Relative Error %',fontsize=20)
ax_vertex.tick_params(axis="y", labelsize=18)
ax_vertex.tick_params(axis="x", labelsize=18)
#add title
fig.suptitle(title_info,fontsize=18)
#show plot
plt.show()
timestr = time.strftime("%Y%m%d-%H%M%S")
if (save):
fig.savefig("output/plots/comparison/"+filename+timestr+".eps",format='eps',bbox_inches="tight")
def plot_comparison(data_dir, filename, title_info):
X = []
Y= []
Z = []
for i,dir in enumerate(data_dir):
tempX, tempY, tempZ = populate_data(dir)
X.append(tempX)
Y.append(tempY)
Z.append(tempZ)
save = True
make_plot_edge (X,Y,filename, title_info, save)
# make_plot_vertex(Z,Y,filename, title_info, save)
if __name__ == "__main__":
file_name = []
title_info = []
tag ="/"
# tag = "/vertex/"
# f_name = "soc-flickr-und"
# file_name.append(f_name)
# title_info.append(f_name + ": 16M edges, 1.7M vertices")
# f_name = "socfb-A-anon"
# file_name.append(f_name)
# title_info.append(f_name + ": 24M edges, 3M vertices")
f_name = "soc-orkut"
file_name.append(f_name)
# title_info.append(f_name + ": 3M vertices")
title_info.append(f_name + ": 31M edges")
# f_name = "soc-sinaweibo"
# file_name.append(f_name)
# title_info.append(f_name + ": 260M edges")
#
# f_name = "soc-twitter-konect"
# file_name.append(f_name)
# title_info.append(f_name + ": 1.2B edges, 41M vertices")
#
# f_name = "soc-friendster"
# file_name.append(f_name)
# title_info.append(f_name + ": 1.8B edges, 65M vertices")
algo_list = []
algo_list.append("EstTriByRWandWghtedSampling")
algo_list.append("EstTriByEdgeSampleAndCount")
algo_list.append("EstTriByRWAndCountPerEdge")
algo_list.append("EstTriByUniformSampling")
for i,file in enumerate(file_name):
data_dir = []
out_filename = file + "-comparison-"
for j,algo in enumerate(algo_list):
data_dir.append("output/plot_data/comparison_plot_data/"+file+".edges/"+algo+tag)
plot_comparison(data_dir, out_filename, title_info[i])