-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlabel_list_process.py
131 lines (108 loc) · 3.98 KB
/
label_list_process.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
import csv
import json
import copy
from math import *
import numpy as np
from matplotlib import pyplot as plt
import pandas as pd
from itertools import islice
def find_max_index(ari_list, max_num):
t = copy.deepcopy(ari_list)
max_number = []
max_index = []
for _ in range(max_num):
number = max(t)
index = t.index(number)
t[index] = 0
max_number.append(number)
max_index.append(index)
return max_index
def find_min_index(ari_list, min_num):
t = copy.deepcopy(ari_list)
min_number = []
min_index = []
for _ in range(min_num):
number = min(t)
index = t.index(number)
t[index] = float("inf")
min_number.append(number)
min_index.append(index)
return min_index
def read_label_list_csv(csv_str, rate, find_len):
inter_rate = []
with open(csv_str)as f:
f_csv = csv.reader(f)
i = 0
for row in f_csv:
i += 1
# print("i:", i)
if i > 1:
real_list = json.loads(row[1])
eval_list = json.loads(row[2])
len_list = len(real_list)
max_real_index_list = find_max_index(real_list,find_len)
max_eval_index_list = find_max_index(eval_list,find_len )
inter_set = list(set(max_real_index_list).intersection(set(max_eval_index_list)))
inter_rate.append(len(inter_set)/find_len)
print("mean:", sum(inter_rate)/len(inter_rate))
return inter_rate
def graw_all():
x = np.arange(1, 30, 2)
y = []
for i in x:
real_list = read_label_list_csv("label_list\\label_list_BA_1000.csv", i, i)
y.append(real_list)
plt.plot(x, y, label="sigmoid")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()
plt.show()
def statistics():
node_num = [50, 100, 250, 500, 1000,2500]
all_real_list = []
all_node_num = []
for num in node_num:
real_list = read_label_list_csv("label_list\\label_list_SM_" + str(num) + ".csv", 0.1, 15)
node_num_list = [str(num)] * len(real_list)
all_real_list = all_real_list + real_list
# all_real_list = [1-x for x in all_real_list]
all_node_num = all_node_num + node_num_list
print(all_node_num)
dataframe = pd.DataFrame({"node num": all_node_num, "overlap rate": all_real_list})
dataframe.to_csv("raincloud\\WS.csv", index=False, sep=',')
def all_net_stats():
net_list = ["BA", "WS", "ER", "RR"]
net_name = []
all_satis_label = []
for net in net_list:
csv_str = "raincloud\\"+net+".csv"
satis_label = []
i = 0
with open(csv_str)as f:
f_csv = csv.reader(f)
if net == "BA":
for row in islice(f_csv, 1, None):
if int(row[0])==2500 and float(row[1])>0.65:
satis_label.append(row[1])
net_name = net_name + ["BA"]*len(satis_label)
all_satis_label = all_satis_label + satis_label
elif net == "RR":
for row in islice(f_csv, 1, None):
if int(row[0])==2500 and float(row[1])>0.65:
satis_label.append(float(row[1]))
net_name = net_name + ["RR"] * len(satis_label)
all_satis_label = all_satis_label + satis_label
else:
for row in islice(f_csv, 1, None):
if int(row[0])==2500 and float(row[1])>0.70:
satis_label.append(row[1])
net_name = net_name + [net] * len(satis_label)
all_satis_label = all_satis_label + satis_label
net_name = net_name + net_name
all_satis_label = all_satis_label + all_satis_label
print("net_name:", net_name)
print("satis_label", all_satis_label)
dataframe = pd.DataFrame({"Network": net_name, "Overlap Ratio": all_satis_label})
dataframe.to_csv("raincloud\\all_2500.csv", index=False, sep=',')
if __name__ == '__main__':
all_net_stats()