-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathim_eval_spread_for_tv.py
64 lines (51 loc) · 1.93 KB
/
im_eval_spread_for_tv.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
import os
import random
import evaluate
import json
from networkx.readwrite import json_graph
import time
from networkx.readwrite import json_graph
import evaluate_spread
import sys
num_mc_simulation = 10000
graphs_to_eval = [
# "GraphSAGE-master/real_data/large_youtube2/large_graph",
#"GraphSAGE-master/real_data/large_youtube/large_graph"]
"GraphSAGE-master/real_data/youtube/TV/test/large_graph"]
for graph_path in graphs_to_eval:
for sampling_freq in[0.003]:# [0.0005,0.001,0.003, 0.005,0.007,0.010,0.05,0.1]:
for budget in [10]:#,50,100,150,200]:#,50,100,150,200]:
#try:
print(sampling_freq)
print(budget)
graph_rl_file = graph_path+"-result_RL_{}_nbs_{}".format(budget, sampling_freq)
print(" graph", graph_path)
solution_file = open(graph_rl_file, "r")
optimal_nodes = solution_file.readlines()
int_selected_nodes = []
for node_i in optimal_nodes:#range(0, budget):
int_selected_nodes.append(int(node_i))
# print( appeared_count)
spread = 0
print(" loading graph")
graph_json_path = graph_path + "-G.json"
# G_data = json.load(open(graph_json_path))
# G = json_graph.node_link_graph(G_data)
print("caculating spread, num of sim", num_mc_simulation)
# for i in range(0, num_mc_simulation):
# G_Copy = G.copy()
spread = evaluate_spread.evaluate_helper_mp(graph_path, None, int_selected_nodes, num_mc_simulation)
# print(" iter {} spread {}".format(i, temp_spread))
# spread = spread + temp_spread
# spread = spread * 1.0 / num_mc_simulation
print('Average Spread = ', spread)
#print('Spread = ', spread)
reward_file_name = graph_path+"_reward_RL_budget_"+str(budget)+"_nbs_"+str(sampling_freq)
print(reward_file_name)
print(reward_file_name)
reward_file = open(reward_file_name, 'w')
reward_file.write(str(spread) )
reward_file.close()
#except :
pass
#print("error")