Does node2vec provide support for edges with negative weights? I have an edgelist with several edges which are negative valued, but I'm strangely getting ZeroDivisionError on running the code. There are no zero edges, however, I checked.
Edit: was asked to share code. I've made no changes to the original repo, so I'm pasting here the exact lines throwing the error.
unnormalized_probs = []
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)
norm_const = sum(unnormalized_probs)
normalized_probs = [float(u_prob)/norm_const for u_prob in unnormalized_probs]
Getting the ZeroDivisionError error in the last line. My edgelist which goes as input to this, is written as follows:
0 0 1
234 11 -2
12 0 -1
The zero-valued nodes aren't a problem, they weren't before when I was running the code on positive node values.
I figured this out. The weight values (stored in unnormalized probabilities) are being added to get a value called 'norm_const', which is then dividing the unnormalized probs. So since they're being added, possibility of zero happening arises, hence zero division error.