aditya-grover / node2vec

http://snap.stanford.edu/node2vec/
MIT License
2.6k stars 912 forks source link

Possible issue in get_alias_edge #71

Open cohmoti opened 5 years ago

cohmoti commented 5 years ago

In get_alias_edge, the probabilities of node neighbors are calculated, based on the last visited edge. The code that calculates this is:

for dst_nbr in sorted(G.neighbors(dst)):
    if dst_nbr == src:
        unnormalized_probs.append(G[dst][dst_nbr]['weight']/p)
    elif G.has_edge(dst_nbr, src):
        unnormalized_probs.append(G[dst][dst_nbr]['weight'])
    else:
        unnormalized_probs.append(G[dst][dst_nbr]['weight']/q)

in the second case, I think this should be:

elif G.has_edge(**src, dst_nbr**):
        unnormalized_probs.append(G[dst][dst_nbr]['weight'])

In the paper this is represented as the distance from t to x is equal to one, here t == src, and x == dst_nbr. In an undirected graph this does not change anything but in a directed one it does.