in utils.py [0:0]
def PPR(A, edge_index):
# The Personalized PageRank heuristic score.
# Need install fast_pagerank by "pip install fast-pagerank"
# Too slow for large datasets now.
from fast_pagerank import pagerank_power
num_nodes = A.shape[0]
src_index, sort_indices = torch.sort(edge_index[0])
dst_index = edge_index[1, sort_indices]
edge_index = torch.stack([src_index, dst_index])
#edge_index = edge_index[:, :50]
scores = []
visited = set([])
j = 0
for i in tqdm(range(edge_index.shape[1])):
if i < j:
continue
src = edge_index[0, i]
personalize = np.zeros(num_nodes)
personalize[src] = 1
ppr = pagerank_power(A, p=0.85, personalize=personalize, tol=1e-7)
j = i
while edge_index[0, j] == src:
j += 1
if j == edge_index.shape[1]:
break
all_dst = edge_index[1, i:j]
cur_scores = ppr[all_dst]
if cur_scores.ndim == 0:
cur_scores = np.expand_dims(cur_scores, 0)
scores.append(np.array(cur_scores))
scores = np.concatenate(scores, 0)
return torch.FloatTensor(scores), edge_index