You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
NetworkX only provides the K-Clique algorithm for community detection, despite past efforts to add more options such as Louvain Modularity. These efforts should be completed and integrated into the main branch.
Current Status
Code for louvain community detection has been submitted and partially tested in #239. This code appears to be maintained by @taynaud on bitbucket
@bjedwardsproposed to add several community detection methods during Summer of Code 2011. The directed laplaian portion of this was eventually merged via #741, but it appears that this was the only portion of the proposal that was completed.
I think what's needed to merge this and other similar projects in future, is a definitive decision on what the structure returned by such algorithms should look like. If I remember correctly the louvain code returns a dictionary, where keys are module indices and values are lists with the respective nodes. A list of sets with nodes belonging to one cluster also seems a sensible structure.
I don't know if there any preferences out there but I strongly believe that a unified return structure should be implemented in order to make the detection algorithms interchangeable.
K-clique is currently the only community algorithm and has been satisfactorily tested #640. There are currently no issues reporting problems with this interface, and using the existing interface would protect existing code. Let's not invent a new standard if we don't have to.
Most community algorithms produce groupings that are not ordered or named, so list and dict datatypes add superfluous structure. @taynaud's work needs a dict to work with a dendogram internally, which is a more complex structure but does not need to be returned to the user in most cases. Thus a collection of of sets, as used in K-clique and @bjedwards code, seems sufficient.
k-clique and @bjedwards differ mainly in their strictness (yield frozenset vs return list of sets). The k-implementation clique seems a bit excessive. The communities of a graph are very often used together (e.g. to color the nodes) so there is little to be gained by using a generator. Similarly, users may want to modify the returned communities, which is inconvenient when the algorithm returns an immutable frozenset.
I suggest that we require that community detection algorithms must return an iterable object that yields objects that support set operations. Both k-clique and @bjedwards are correct under this definition, but @taynaud's would need to be modified.
Thanks @SuperAce99 for the clear summary. I agree with you on the data structure ( iterable object that yields objects that support set operations) and I think we should proceed that way.
That handles the case of overlapping partitions easily too.
There are likely some operations that are easier to perform with an inverted representation like a dict with labeled communities. In particular finding which group a node is in. But it is straightforward to convert to that structure if needed.
Just wanted to chime in. I am +1 for an iterable object that yields objects that support set operations. I would argue for set instead of frozenset.
Most algorithms will create communities iteratively, meaning that most would require the construction of a set only to have it recast to a frozenset before yielding. Though I suppose we could leave those details up to whoever writes the algorithm.
In some cases having hashable communities might be useful. If information about the communities is also provided by the algorithm, or if information is to be added later it would be useful to return a dict keyed by frozenset communities. But I think @hagberg 's suggestion to convert it to a dict of labeled communities (through a provided function or by the user) is straightforward.
Glad to see this discussion happening. @hagberg's point about overlapping partitions is spot on for me. I'd want the data structure returned by such an algorithm to be similar to the rest of the community detection algorithms.
Also, if conversion to dict or frozensets was super important, NetworkX could provide some functions that receive the output and convert them appropriately. They wouldn't need to be imported into the top level module networkx, but we could make them available networkx.algorithms.community. This would save people from typing the same boilerplate conversion each time.
One other option @hagberg and I considered when I first started the community work was a new class Community. This could have some of the built in functionality like affiliation representations. I messed with the idea at first but we decided it was probably a little more than we needed. A rough implementation can be found here.
It built heavily on the Graph class as it was at the time. I am not necessarily advocating for this, but it is an option...
I have recently started working on Brainx. We have implemented two community finding algorithms (Simulated Annealing, Newmans Spectral Partitioning from 2006 PNAS paper).
This code has implemented a GraphPartition class, and returns the partition GraphPartition.index as a dict of sets, keys are just ints 0->number_of_partitions. I have been doing quite a bit of refactoring on this code recently, and one of the main issues is moving away from a dict, to a list of sets. This is primarily to benefit the algorithms, but this lack of structure is in some ways more intuitive. Having a frozenset as a final result is appealing, but agree it would be nice to have some nice functions for converting.
I was planning on submitting a pull request after I finish (somehwhat substantial) refactoring of the code, but wanted to chime in on this discussion in case our experience is useful. I have been meaning to look at @taynaud python-louvain implementation, to gain inspiration for the GraphPartition class, and (thanks to this discussion) also plan to look at @haberg Community class; this discussion is timely.
Activity
hagberg commentedon Sep 12, 2013
Yes, we could add that code to NetworkX. PR welcome.
Midnighter commentedon Sep 16, 2013
I think what's needed to merge this and other similar projects in future, is a definitive decision on what the structure returned by such algorithms should look like. If I remember correctly the louvain code returns a dictionary, where keys are module indices and values are lists with the respective nodes. A list of sets with nodes belonging to one cluster also seems a sensible structure.
I don't know if there any preferences out there but I strongly believe that a unified return structure should be implemented in order to make the detection algorithms interchangeable.
SuperAce99 commentedon Sep 16, 2013
I agree that a standard structure is needed. The existing interfaces are:
yieldsafrozensetof node IDs until all communities have been yielded.returnalistofsetsof node IDs.returnsadict"with communities numbered from 0 to number of communities."K-clique is currently the only community algorithm and has been satisfactorily tested #640. There are currently no issues reporting problems with this interface, and using the existing interface would protect existing code. Let's not invent a new standard if we don't have to.
Most community algorithms produce groupings that are not ordered or named, so
listanddictdatatypes add superfluous structure. @taynaud's work needs adictto work with a dendogram internally, which is a more complex structure but does not need to be returned to the user in most cases. Thus a collection of of sets, as used in K-clique and @bjedwards code, seems sufficient.k-clique and @bjedwards differ mainly in their strictness (
yield frozensetvsreturn listofsets). The k-implementation clique seems a bit excessive. The communities of a graph are very often used together (e.g. to color the nodes) so there is little to be gained by using a generator. Similarly, users may want to modify the returned communities, which is inconvenient when the algorithm returns an immutablefrozenset.I suggest that we require that community detection algorithms must return an iterable object that yields objects that support set operations. Both k-clique and @bjedwards are correct under this definition, but @taynaud's would need to be modified.
hagberg commentedon Sep 17, 2013
Thanks @SuperAce99 for the clear summary. I agree with you on the data structure ( iterable object that yields objects that support set operations) and I think we should proceed that way.
That handles the case of overlapping partitions easily too.
There are likely some operations that are easier to perform with an inverted representation like a dict with labeled communities. In particular finding which group a node is in. But it is straightforward to convert to that structure if needed.
bjedwards commentedon Sep 17, 2013
Just wanted to chime in. I am +1 for an iterable object that yields objects that support set operations. I would argue for
setinstead offrozenset.Most algorithms will create communities iteratively, meaning that most would require the construction of a
setonly to have it recast to afrozensetbefore yielding. Though I suppose we could leave those details up to whoever writes the algorithm.In some cases having hashable communities might be useful. If information about the communities is also provided by the algorithm, or if information is to be added later it would be useful to return a dict keyed by
frozensetcommunities. But I think @hagberg 's suggestion to convert it to a dict of labeled communities (through a provided function or by the user) is straightforward.chebee7i commentedon Sep 17, 2013
Glad to see this discussion happening. @hagberg's point about overlapping partitions is spot on for me. I'd want the data structure returned by such an algorithm to be similar to the rest of the community detection algorithms.
Also, if conversion to dict or frozensets was super important, NetworkX could provide some functions that receive the output and convert them appropriately. They wouldn't need to be imported into the top level module
networkx, but we could make them availablenetworkx.algorithms.community. This would save people from typing the same boilerplate conversion each time.bjedwards commentedon Sep 17, 2013
One other option @hagberg and I considered when I first started the community work was a new class
Community. This could have some of the built in functionality like affiliation representations. I messed with the idea at first but we decided it was probably a little more than we needed. A rough implementation can be found here.It built heavily on the
Graphclass as it was at the time. I am not necessarily advocating for this, but it is an option...cindeem commentedon Sep 17, 2013
I have recently started working on Brainx. We have implemented two community finding algorithms (Simulated Annealing, Newmans Spectral Partitioning from 2006 PNAS paper).
This code has implemented a
GraphPartitionclass, and returns the partitionGraphPartition.indexas a dict of sets, keys are just ints 0->number_of_partitions. I have been doing quite a bit of refactoring on this code recently, and one of the main issues is moving away from a dict, to a list of sets. This is primarily to benefit the algorithms, but this lack of structure is in some ways more intuitive. Having afrozensetas a final result is appealing, but agree it would be nice to have some nice functions for converting.I was planning on submitting a pull request after I finish (somehwhat substantial) refactoring of the code, but wanted to chime in on this discussion in case our experience is useful. I have been meaning to look at @taynaud python-louvain implementation, to gain inspiration for the
GraphPartitionclass, and (thanks to this discussion) also plan to look at @haberg Community class; this discussion is timely.Just wanted to add my 2c
hagberg commentedon Sep 18, 2013
It seems we are all in agreement on how to proceed. So bring on the pull requests 👍
SuperAce99 commentedon Sep 20, 2013
Working on it! (and trying not to bump the
closebutton...)stared commentedon Jan 28, 2014
+1
harrismirza commentedon Mar 31, 2019
Is there any update on this? Seems to be held up but I can't quite work out why.
dschult commentedon Mar 31, 2019
Looks like it is waiting for code to be submitted as a Pull Request.