@@ -195,6 +195,11 @@ class LouvainCommunityDetection(object):
195
195
minimum threshold value for change in modularity
196
196
default(0.0000001)
197
197
198
+ Methods
199
+ -------
200
+ run()
201
+ run the algorithm to find partitions at multiple levels
202
+
198
203
Examples
199
204
--------
200
205
>>> louvain = LouvainCommunityDetection(graph)
@@ -211,17 +216,30 @@ class LouvainCommunityDetection(object):
211
216
"""
212
217
213
218
def __init__ (self , graph , communities = None , minthr = 0.0000001 ):
219
+ """initialize the algorithm with a graph and (optional) initial
220
+ community partition , use minthr to provide a stopping limit
221
+ for the algorith (based on change in modularity)"""
214
222
self .graph = graph
215
223
self .initial_communities = communities
216
224
self .minthr = minthr
217
225
218
226
def run (self ):
219
- dendogram = self .gen_dendogram ()
220
- partitions = self .partitions_from_dendogram (dendogram )
227
+ """ run the algorithm
228
+
229
+ Returns
230
+ -------
231
+ partitions : list
232
+ a list containing instances of a WeightedPartition with the
233
+ community partition reflecting that level of the algorithm
234
+ The last item in the list is the final partition
235
+ The first item was the initial partition
236
+ """
237
+ dendogram = self ._gen_dendogram ()
238
+ partitions = self ._partitions_from_dendogram (dendogram )
221
239
return [WeightedPartition (self .graph , part ) for part in partitions ]
222
240
223
241
224
- def gen_dendogram (self ):
242
+ def _gen_dendogram (self ):
225
243
"""generate dendogram based on muti-levels of partitioning
226
244
"""
227
245
if type (self .graph ) != nx .Graph :
@@ -336,7 +354,7 @@ def _move_node(part, node, new_comm):
336
354
new_community = [x for x in new_community if len (x ) > 0 ]
337
355
return WeightedPartition (part .graph , new_community )
338
356
339
- def partitions_from_dendogram (self , dendo ):
357
+ def _partitions_from_dendogram (self , dendo ):
340
358
""" returns community partitions based on results in dendogram
341
359
"""
342
360
all_partitions = []
0 commit comments