-
Notifications
You must be signed in to change notification settings - Fork 433
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for edge weights to GraphSAGE sampling #1667
Conversation
9f2e23f
to
c362597
Compare
1aa7f14
to
887b4ad
Compare
Code Climate has analyzed commit 7b86b92 and detected 4 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
stellargraph/data/explorer.py
Outdated
else: | ||
neighbours = [] | ||
|
||
if len(neighbours) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should do something like:
if len([w for w in weights if w != 0]) == 0:
so that we still have -1
s propagated if all neighbours have zero weight?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, that's a good point. That particular form is likely to be expensive because it's manually iterating the array, but it's probably worth doing something with https://docs.scipy.org/doc/numpy/reference/generated/numpy.count_nonzero.html or using the final value of the cumsum
in naive_weighted_choice
. I'll probably do it in the latter, because then it applies to weighted Node2Vec too (which currently doesn't handle this case).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, and fixed/tested in Node2Vec and CTDNE as appropriate as well.
@@ -1117,6 +1128,8 @@ def _step(self, node, time, bias_type, np_rs): | |||
if len(neighbours) > 0: | |||
biases = self._temporal_biases(times, time, bias_type, is_forward=True) | |||
chosen_neighbour_index = self._sample(len(neighbours), biases, np_rs) | |||
assert chosen_neighbour_index is not None, "biases should never be all zero" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
This expands GraphSAGE (undirected and directed) to support weighted sampling, where edges with higher weights are taken proportionally more often.
For example, suppose there's there's 4 edges from node A:
An unweighed walk starting at A will choose each of the edges with equal propability and so end up on B, C or D in proportion 1:1:2 (edge counts). A weighted walk will choose the edges proportional to the weights, so end up on the vertices in proportion 0:1:5 (sum of edge weight). (Worth specifically highlighting: a weighted walk will never chose the A-B edge because it has weight 0.)
See: #462