Skip to content

Add k-clique community algorithm (migrated from Trac #652) #640

Closed

Activity

  1. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @conradlee, 2011-11-06

    Oops, somehow this comment got duplicated--see comment below.

  2. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by conradlee, 2011-11-06

    You might put this in the same file as find_cliques, but I would say makes sense to create a file called percolate.py (perhaps in a community finding subfolder?). There are other types of percolation on cliques (or other objects), and those could be implemented in the same percolate.py file.

    Note also that only cliques of size k or larger need to be found. Thus, if it's easy to change the find_cliques function to have a minimum size argument, this could speed up clique finding for the purposes of clique percolation.

    In that gist code I've tried to include a doctest, but I don't really know what I'm doing. I just saw one mentioned the other day in a persentation, so I thought maybe NetworkX uses them as well---if not, then you can remove that example in the docstring.

  3. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Attachment in Trac by @hagberg, 2011-11-06: kclique.patch

  4. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-11-06

    Here is a patch to include that code with some light changes - naming, header, doctest, documentation, nose test.

  5. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-11-14

    Added in [1978/networkx]

  6. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by Aric Hagberg <aric.hagberg, 2011-11-14

    In [7143955/networkx]:
    '''
    #!CommitTicketReference repository="networkx" revision="7143955d6d2b6535b4a84d05c6902ac884065047"
    Add init for community.
    Addresses #652
    '''

  7. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by Aric Hagberg <aric.hagberg, 2011-11-14

    In [10cf64e/networkx]:
    '''
    #!CommitTicketReference repository="networkx" revision="10cf64e27d6df99760383dda89debfdafa368eb7"
    Fix doctest to work with python2 and python3
    Addresses #652
    '''

  8. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by Aric Hagberg <aric.hagberg, 2011-11-14

    In [c2e70f7/networkx]:
    '''
    #!CommitTicketReference repository="networkx" revision="c2e70f7a0413e33e9e1f374437baa928383ff56d"
    fix python 2/3 issue in test
    Addresses #652
    '''

  9. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-11-20

  10. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @conradlee, 2011-11-23

    There is a bug in this code that a friend of mine caught.

    Basically, all cliques of size k should be part of some community in the end, but in the current code only the cliques that percolate are included in communities.

    If you add one line you can fix this bug.

    '''
    ...
    perc_graph = nx.Graph()
    perc_graph.add_nodes_from(cliques) # added line
    for clique in cliques:
    ...
    '''

  11. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by Aric Hagberg <aric.hagberg, 2011-11-24

    In [4b39686/networkx]:
    '''
    #!CommitTicketReference repository="networkx" revision="4b39686d7c047b0a70cca27f82ef6e5356112620"
    Make sure all cliques of size k are in community.
    Addresses #652
    '''

  12. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-11-24

    I added that fix and updated the tests.
    Can you look to make sure the tests are correct?

  13. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @conradlee, 2011-11-24

    Yes, the additional test looks correct and would catch the bug if it were re-introduced.

    Maybe we should include a more extensive test. For example, I could run a smallish network like Zachary's Karate club through both CFinder and SCP (two implementations of clique percolation) and make sure that their results are the same. We could then use those results as the expected output of the networkx implementation.

    How does that sound? If you like that idea, do you have any proposals for the test network? I guess it should be big enough that a buggy implementation is likely to do something wrong, but small enough to not bog down a long list of tests.

  14. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-11-24

    More tests are always helpful.
    Your idea of the Zachary graph is good - we already have nx.karate_club_graph() so we just need the correct answer for various k.
    Other ideas for tests are corner cases (empty graph, isolated cliques, etc.)

  15. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @conradlee, 2011-12-07

    I've added the Zachary's karate club test: https://gist.github.com/1443573
    The expected output is based on the sequential clique percolation code located here: http://www.lce.hut.fi/~mtkivela/kclique.html

    Can we be confident that the ground truth output is bug-free? I think so. Some researchers in my group are benchmarking a number of clique percolation techniques, and found that implementation to be bug-free, as in its output exactly matches to the output of two other clique percolation methods. (Except for the case where k=2, which corresponds to connected components--the sequential clique percolation incorrectly returns an empty set in that case).

    We might want to raise an exception if the user attempts to use any value less than 2 for the value of k. We might want to raise a warning if the user selects 2 for the value of k (as this is quite a trivial--it asks which edges percolate into each other, which is equivalent to finding connected components).

  16. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by Aric Hagberg <aric.hagberg, 2011-12-07

    In [c9188c7/networkx]:
    '''
    #!CommitTicketReference repository="networkx" revision="c9188c78da82cbe49e8f47871194597c48b81328"
    Add Zachary test.
    Addresses #652
    '''

  17. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-12-07

    Thanks for the test; I added it.

    Instead of an error should the k=1 case return an empty list? Or a list of one set for each node?

    I think the k=2 case is OK as is (doesn't need a warning since it produces a correct but maybe not very interesting answer).

  18. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @conradlee, 2011-12-07

    Instead of an error should the k=1 case return an empty list? Or a list of one set for each node?

    I think the k=1 case should work as follows: The cliques are single nodes (and all larger cliques). As usual, a pair of cliques percolate if they share k-1 (i.e., zero) nodes. Thus all cliques percolate into each other, and the algorithm should return on single community: all nodes in the graph (even if the graph is not connected).

    However, this is not the behavior that will come out of the current implementation, because the find_cliques method does not return single nodes as cliques---the smallest cliques it returns are edges. In the implementation we could solve this problem by handling the k=1 case sepratately. Or we could raise an error. Is a 1-clique actually a clique? Not according to the find_cliques function.

  19. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2011-12-07

    Replying to [comment:17 conradlee]:

    Instead of an error should the k=1 case return an empty list? Or a list of one set for each node?

    I think the k=1 case should work as follows: The cliques are single nodes (and all larger cliques). As usual, a pair of cliques percolate if they share k-1 (i.e., zero) nodes. Thus all cliques percolate into each other, and the algorithm should return on single community: all nodes in the graph (even if the graph is not connected).

    However, this is not the behavior that will come out of the current implementation, because the find_cliques method does not return single nodes as cliques---the smallest cliques it returns are edges. In the implementation we could solve this problem by handling the k=1 case sepratately. Or we could raise an error. Is a 1-clique actually a clique? Not according to the find_cliques function.

    I think you are right - a clique should have at least one edge...

    I suggest we force k>=2 and raise an exception if not.

  20. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by Aric Hagberg <aric.hagberg, 2011-12-08

    In [4331cbc/networkx]:
    '''
    #!CommitTicketReference repository="networkx" revision="4331cbc4eacf11d62b2ccf38efdfbec6edd65895"
    Raise error if k < 2.
    Addresses #652
    '''

  21. networkx-trac commented on Jul 20, 2012

    @networkx-trac
    Author

    Comment in Trac by @hagberg, 2012-04-08

  22. added this to the networkx-1.9 milestone on May 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions