Skip to content

Link prediction algorithms - #1117

Merged
chebee7i merged 34 commits into
networkx:masterfrom
kmkurn:link-prediction
Apr 29, 2014
Merged

chebee7i merged 34 commits into
networkx:masterfrom
kmkurn:link-prediction

Conversation

@kmkurn

@kmkurn kmkurn commented Apr 21, 2014

Copy link
Copy Markdown

I tried to implement some simple link prediction algorithms which I am going to use in my work. Complete list of well-known algorithms can be found here. Some link prediction algorithms based on cluster information are emerging recently (here and here) so I am thinking of implementing some of them too.

This request is NOT ready to be merged. Many improvements are still needed. Please let me know if you're interested by leaving any comments.

@chebee7i

Copy link
Copy Markdown
Member

This is looking great, and definitely a welcome contribution. There's been some interest in this too (mailing list).

@hagberg

hagberg commented Apr 21, 2014

Copy link
Copy Markdown
Member

Yes, definitely interesting. And A+ for writing more code for tests than the algorithms :-).
Let us know how we can help.

@hagberg hagberg added this to the networkx-future milestone Apr 21, 2014
@hagberg hagberg self-assigned this Apr 21, 2014
@kmkurn

kmkurn commented Apr 22, 2014

Copy link
Copy Markdown
Author

Thanks for your warm comments :)

First probably I want to hear your opinion about what I have in mind:

  1. Most link prediction algorithms only apply to undirected graph so I'll probably only throw an exception (NetworkXNotImplemented?) for any other types of network.
  2. Functions to predict links in predict.py will return a dictionary with non-existent edge as the key and its node similarity/occurrence probability as the value. Since this is an undirected graph, I am thinking of including both edge (u, v) and (v, u) in the dictionary. But I am still not sure about this. What do you think is better?
  3. In case of link prediction enhanced with community information, few things are assumed: a community is defined over nodes NOT edges, a node can only belong to one community, and community information is stored as node attribute with the name community. I wonder if it would be better to pass the community information to the link prediction function (defined in predict.py) directly.

Those issues are what I could think of right now. Please let me know what you think.

As for the tests, I am thinking of adding more tests actually. 😉

@hagberg

hagberg commented Apr 22, 2014

Copy link
Copy Markdown
Member
  1. Yes, if the algorithm doesn't apply for directed graphs it is a good idea to warn the user
  2. How about using a generator approach and yielding (u,v,p) or (u,v,{probability:p|) or... ?
    That way you don't have to explicitly build a dictionary (more efficient) and the edges can be easily passed to other functions like G.add_edges_from(). No need to repeat the edge v-u for u-v either.
  3. We'll probably need to see how the code works first

@kmkurn

kmkurn commented Apr 23, 2014

Copy link
Copy Markdown
Author

I have coded so that link prediction only available to simple undirected graph and used the generator approach as you suggested. The generator will yield tuple (u, v, p). I have also coded some community-based link prediction algorithms. However, there are two issues:

  1. Using generator approach means that exception throwing will be delayed until the problematic pair of nodes is processed.
  2. Partial community information is allowed: if there is enough information to compute the score of a pair of nodes then the algorithm will work. In other words, it is not always necessary for all the nodes to belong to a community.

Please let me know what you think.

@ysitu

ysitu commented Apr 23, 2014

Copy link
Copy Markdown
Contributor

An algorithm should not return a generator. A generator creates an invisible dependency on the graph that lingers even after the algorithm has ended. An inadvertent user will be surprised when the generator raises an exception after he/she modifies the graph.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to litter the code with this check everywhere. Just put @not_implemented_for('undirected') from networkx.utils on the entry points.

Comment thread networkx/algorithms/link_prediction.py Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "within- and inter-cluster common neighbors"? Also consider adding hyphens to "within" and "inter" where appropriate below.

@kmkurn

kmkurn commented Apr 29, 2014

Copy link
Copy Markdown
Author

Done. Thanks for the corrections @ysitu. Any other things need to be fixed?

@chebee7i

Copy link
Copy Markdown
Member

Ready to merge, I think.

@ysitu

ysitu commented Apr 29, 2014

Copy link
Copy Markdown
Contributor

Looks good to me.

chebee7i added a commit that referenced this pull request Apr 29, 2014
@chebee7i
chebee7i merged commit 1e35cb7 into networkx:master Apr 29, 2014
@kmkurn
kmkurn deleted the link-prediction branch April 30, 2014 05:42
@ysitu

ysitu commented May 9, 2014

Copy link
Copy Markdown
Contributor

Need to add documentation to HTML/PDF references.

@kmkurn

kmkurn commented May 9, 2014

Copy link
Copy Markdown
Author

What kind of documentation is needed? I looked at the HTML/PDF references and it seems that the documentation was generated automatically from the docstring.

@ysitu

ysitu commented May 10, 2014

Copy link
Copy Markdown
Contributor

It seems that the functions added in this PR are not included in the documentation. Typically the Sphinx source files need to be manually edited to include newly added functions.

@kmkurn

kmkurn commented May 10, 2014

Copy link
Copy Markdown
Author

I see. But the thing is, I am not familiar with Sphinx and how it is used here. If you could tell me specifically what to do that would be very much appreciated. I already looked at .rst files in doc/source but I think it is not enough.

@ysitu

ysitu commented May 10, 2014

Copy link
Copy Markdown
Contributor

No worry. Those are trivial changes and are covered in #1148.

@kmkurn

kmkurn commented May 10, 2014

Copy link
Copy Markdown
Author

Nice :-)

Btw, what do you say about implementing other basic link prediction algorithms? In the original paper, there are some algorithms that haven't been implemented in this PR. I could initiate another PR to code some of them.

@ysitu

ysitu commented May 10, 2014

Copy link
Copy Markdown
Contributor

That is outside my area of expertise. Maybe other maintainers can chime in.

@chebee7i

Copy link
Copy Markdown
Member

I'd say go for it (in another PR). Is this and #1148 ready to be merged?

Update: Hahah, I had merged this already!

@ysitu

ysitu commented May 10, 2014

Copy link
Copy Markdown
Contributor

@chebee7i #1148 is ready.

@ysitu ysitu modified the milestones: networkx-1.9, networkx-future May 30, 2014
@ysitu ysitu mentioned this pull request May 31, 2014
@Mjh9122 Mjh9122 mentioned this pull request Apr 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants