-
Notifications
You must be signed in to change notification settings - Fork 0
/
artsim.py
81 lines (63 loc) · 2.98 KB
/
artsim.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
import sys
import numpy as np
from ArtSimCore import ArtSimCore
from rank_distance import tau, ndcg
import pandas as pd
import time
dblp_fcc = "../data/evaluation/dblp_fcc_varying_future_period_30percent_WITH_ZEROS.txt"
#dblp_fcc = "../data/evaluation/dblp_fcc_varying_future_period_30percent.txt"
if len(sys.argv) != 8 and len(sys.argv) != 9:
print("Usage: python3 artsim.py <paper_details_file> <scores_file> <sim_file_PAP> <sim_file_PTP> <connections_file_PV> <cold_start_year> <eval_method> <ndcg:k>")
sys.exit(-1)
paper_details = sys.argv[1]
scores_file = sys.argv[2]
sim_file_PA = sys.argv[3]
sim_file_PT = sys.argv[4]
con_file_PV = sys.argv[5]
cold_start_year = int(sys.argv[6])
eval_method = sys.argv[7]
k = -1
if eval_method == "ndcg":
if len(sys.argv) != 9:
print("Usage: python3 artsim.py <paper_details_file> <scores_file> <sim_file_PAP> <sim_file_PTP> <connections_file_PV> <cold_start_year> <eval_method> <ndcg:k>")
sys.exit(-1)
k = int(sys.argv[8])
artsim_core = ArtSimCore()
artsim_core.read_paper_ids(paper_details)
artsim_core.read_paper_scores(scores_file)
artsim_core.mark_cold_start_papers(cold_start_year)
artsim_core.read_similarities(sim_file_PA, 'PA')
artsim_core.read_similarities(sim_file_PT, 'PT')
artsim_core.read_connections(con_file_PV, 'PV')
ground_truth_df = pd.read_csv(dblp_fcc, sep='\t', header=None, names=['paper_id', 'truth_score'])
for precision in [1]:
splits = pow(10, precision) + 1
artsim_time = 0
tau_time = 0
for alpha in np.linspace(0, 1, splits):
for beta in np.linspace(0, 1, splits):
for delta in np.linspace(0, 1, splits):
alpha = round(alpha, precision)
beta = round(beta, precision)
gamma = 0
delta = round(delta, precision)
sum = alpha + beta + gamma + delta
if (round(sum, precision) != 1.0):
continue
start = time.time()
results = None
results = artsim_core.run(alpha, beta, gamma, delta)
artsim_time += (time.time() - start)
start = time.time()
result_df = pd.DataFrame(results, columns=['paper_id', 'pred_score'])
eval_score = -1
if eval_method == "tau":
eval_score = tau(ground_truth_df, result_df)
elif eval_method == "ndcg":
eval_score = ndcg(ground_truth_df, result_df, k)
else:
print(eval_method + " is not recognised as a valid evaluation method; please choose one of { tau, ndcg }")
sys.exit(-1)
eval_time += (time.time() - start)
print (str(precision) + "\t" + str(alpha) + "\t" + str(beta) + "\t" + str(gamma) + "\t" + str(delta) + "\t" + str(eval_score))
print(">" + str(artsim_time) + "\t" + str(eval_time))