-
Notifications
You must be signed in to change notification settings - Fork 0
/
fastrp_similarity.py
52 lines (45 loc) · 1.69 KB
/
fastrp_similarity.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
import pyTigerGraph as tg
conn = tg.TigerGraphConnection(host="http://1.1.1.13", graphname="ProviderSimilarity")
preprocess = False
if preprocess:
print("PREPROCESSING")
conn.runInstalledQuery("tg_fastRP_preprocessing", params={"index_attr": "vert_index"}, timeout=4_096_000)
print("Preprossing Complete")
import time
embed = False
if embed:
params = {"num_nodes": 6_815_739,
"num_edges": 16_201_798,
"k": 3,
"sampling_constant": 3,
"reduced_dimension": 200,
"normalization_strength": -0.1,
"input_weights": "1,2,4",
"index_attr": "vert_index",
"print_accum": False,
"result_attr": "fastrp_embedding"}
print("RUNNING FASTRP EMBEDDING")
t1 = time.time()
conn.runInstalledQuery("tg_fastRP", params=params, timeout=1_024_000)
t2 = time.time()
print("Time Elapsed: %.2f Seconds" % (t2-t1))
providers = ["1790766392", "1184626384", "1164424461", "1235131483", "1841292943",
"1578565859", "1871597104", "1629072996", "1083696371", "1790766392"]
times = []
for provider in providers:
params = {"v1": provider,
"v1.type": "Individual",
"vert_types": "Individual",
"embeddingDim": 200,
"k": 10}
t1 = time.time()
res = conn.runInstalledQuery("tg_embedding_cosine_similarity", params=params)[0]["kMostSimilar"]
t2 = time.time()
print("Time Elapsed:", t2-t1)
print("Most Similar to Individual:", provider)
for r in res:
print(r["v_id"], r["attributes"]["@similarityScore"])
print()
times.append(t2-t1)
print("===== Average Time Elapsed =====")
print(sum(times)/len(times), "Seconds")