Repository navigation
Link prediction algorithms #2 - #1163
Conversation
|
I was kinda concerned about this when you put super precise floating-point numbers in docstrings in #1117. Now it finally blows up on Travis. BTW, please add references to the new functions in the Sphinx source files. |
|
Doctests can be painful when they are tested. Nose provides a feature to skip a test on a per line basis by adding I somewhat prefer not to test docstrings, but that has its own problems as well. In documentation (that exists outside the docstrings), if we make use of the IPython Sphinx directive, then you can do things like: And that will test for approximate equality. The rendered output looks clean, something like: So this is another option (but it exists outside docstrings and would only be tested when documentation was built). |
|
Reducing the output precision using |
|
I prefer to test docstrings. It's pretty frustrating to paste in an example and it doesn't work. Testing helps avoid that. But here is another suggestion. For longer examples on how to use a function or module we can create examples in networkx/examples and make a link. |
|
Output precision was fixed and references were added to Sphinx file. Please check. |
|
@kemskems How were you planning on implementing Katz score? Currently all link prediction algorithms are implemented like this: This works fine for the neighbor-based predictors but Katz score, SimRank and others are most easily implemented as matrix operations that calculate scores for all node pairs in one go (similar to the algorithms in So perhaps it makes sense to move to an API like this: which returns a single score if u and v are nodes or a dict if u and/or v is None (u and/or v might even be lists or iterables of nodes, but maybe things become too complex then). Thoughts? |
|
@rafguns I haven't given it much thought yet, but yes I agree that what you said is an issue. A less complex approach probably like this (already discussed in PR #1117): def some_predictor(G, ebunch=None):
if ebunch is None:
ebunch = nx.non_edges(G)
yield tuple_of_scores # e.g. ('a', 'b', 0.5), ('c', 'd', 0.75), ...but then we have another issue for community-based link prediction algorithms: exception will be raised while iterating if there are some edges in |
|
I like the Also, #1117 can improved by allowing the user to specify a data key for community information instead of a hard-coded string ( I am marking this for 1.9 so that any interface change can be applied to #1117 before the latter is released to the wild. |
|
I have implemented the interface change and user is now allowed to specify node community attribute name as suggested. As for the Katz score, I already tried to implement it using the old interface, but changing its interface turned out to be a non-trivial task so I removed it for now. Also, there are some issues I'd like to discuss so perhaps it is better to do it in another PR. Regarding the exception message, I am not sure about the best way to tell user which node that has no community information. Printing the node in the message may not be a good idea since the node could be anything; its string representation might not be meaningful at all. Or the user is supposed to handle this? |
There was a problem hiding this comment.
Change to "iterable of node pairs". Also applies to all other occurrences below.
There was a problem hiding this comment.
node_u = G.node[u]
try:
return node_u[community]
except KeyError:
raise nx.NetworkXAlgorithmError('No community information', u)This avoids punishing the common case where community information is present.
|
I think that this is ready for merging. We can ignore reporting the node without community information for now and add it later if prominent need pops up. |
|
OK 👍 |
This is the sequel of PR #1117. I added Jaccard coefficient, Adamic-Adar index, and preferential attachment score as described here.
I am thinking of adding Katz score too, probably utilizing the existing
katz_centralityfunction, but I am quite busy at the moment. If there's anyone who could help that'll be great. I don't really understand the other algorithms mentioned in the paper so I won't implement it now.