-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdegree_bin_plot.py
More file actions
141 lines (107 loc) · 4.31 KB
/
degree_bin_plot.py
File metadata and controls
141 lines (107 loc) · 4.31 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
import os
import sys
import time
import pandas as pd
import matplotlib.pyplot as plt
import statistics
import numpy as np
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 plot_degree_bin (bin_dir, out_filename, title_info):
# We will go into each directory in the bin_dir list
# and then iterate over each file inside the directory.
# For each file we take the median accuracy and the variance accuracy
#
median_err=[]
variance_err=[]
# Enumerate over each bin
for i,data_dir in enumerate(bin_dir):
# We are inside a bin; Go over each file and collect the median accuracy and variance.
bin_median_error = []
bin_variance_error = []
for i, file in enumerate(os.listdir(data_dir)):
path = os.path.join(data_dir, file)
if os.path.isdir(path):
# skip directories
continue
if not file.startswith('.'):
data_file = data_dir + file
df_median_error = pd.read_csv(data_file, sep=",",skiprows=lambda x: skip_rows_err(x),header=None, usecols=[1,3])
bin_median_error.append(df_median_error.iloc[0,0])
bin_variance_error.append(df_median_error.iloc[0,1])
median_err.append(bin_median_error)
variance_err.append(bin_variance_error)
num_bin = len(bin_dir)
group_len = len(median_err[0])
# Set bar width
barWidth = 0.2
starting_pos = 1
gap = 1
x={}
# Set bar position
for i in range(num_bin):
x[i] = [starting_pos+i*barWidth for i in range(group_len)]
starting_pos = starting_pos + gap + barWidth*group_len
fig, ax = plt.subplots()
plt.subplots_adjust(bottom = 0.2, top = 0.8, right = 0.95, left = 0.1, hspace = 0.38)
ax.bar(x[0], median_err[0], width=barWidth, color='b', edgecolor= "black",label="Gender")
ax.bar(x[1], median_err[1], width=barWidth, color='b', edgecolor= "black",label="Type")
ax.bar(x[2], median_err[2], width=barWidth, color='b', edgecolor= "black",label="Type")
ax.bar(x[3], median_err[3], width=barWidth, color='b', edgecolor= "black",label="Type")
#rects4 = ax.bar(x_4, median_err[4], width=barWidth, color='b', edgecolor= "black",label="Type")
y_min = 0
y_max = 2
ax.set_ylim(y_min,y_max)
# y_ind = [i/2 for i in range(4)]
# y_label = [str(i/2)+'%' for i in range(4)]
# ax.set_yticks(y_ind)
# ax.set_yticklabels(y_label)
ax.set_title(title_info,fontsize=24)
ax.set_ylabel('Median Relative Error (%)',fontsize=20)
ind = [x[i][1] for i in range(num_bin)]
ax.set_xticks(ind)
ax.tick_params(axis="y", labelsize=18)
ax.set_xticklabels(('deg$\in [1,10]$', 'deg$\in [10,10^2]$','deg$\in [10^2,10^3]$', 'deg$\in [10^3,10^4]$'),fontsize=18)
ax.set_xlabel('Degree based buckets',fontsize=24)
plt.show()
timestr = time.strftime("%Y%m%d-%H%M%S")
fig.savefig("output/plots/degree-bin/"+out_filename+"-"+timestr+".eps",format='eps',bbox_inches="tight")
if __name__ == "__main__":
x_max = 1.1
file_name = []
title_info = []
# 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")
# no_bin = 4
# #
f_name = "soc-orkut"
file_name.append(f_name)
title_info.append(f_name + ": 213M edges")
# f_name = "soc-sinaweibo"
# file_name.append(f_name)
# title_info.append(f_name + ": 260M edges, 58M vertices")
#
# f_name = "soc-twitter-konect"
# file_name.append(f_name)
# title_info.append(f_name + ": 2.4B edges")
no_bin = 4
# f_name = "soc-friendster"
# file_name.append(f_name)
# title_info.append(f_name + ": 1.8B edges, 65M vertices")
# #
for i,file in enumerate(file_name):
bin_directory = []
# The main data dirextory
data_dir = "output/plot_data/degree_bin_data/"+file+".edges/EstTriByRWandWghtedSampling/0.3/bin"
for j in range(no_bin):
bin_directory.append(data_dir+'_'+str(j)+'/')
out_filename = file
plot_degree_bin(bin_directory,out_filename,title_info[i])