Skip to content

Commit 436ce6d

Browse files
author
CindeeM
committed
RF: clean up LouvainCommunityDetection docs and methods
1 parent 1b279aa commit 436ce6d

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

brainx/tests/test_weighted_modularity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ def test_gen_dendogram(self):
216216
nodeslist = [0,1,2,3,4]
217217
graph.add_nodes_from(nodeslist, weight=True)
218218
louvain = wm.LouvainCommunityDetection(graph)
219-
self.assertRaises(IOError, louvain.gen_dendogram)
219+
self.assertRaises(IOError, louvain._gen_dendogram)
220220

221221
def test_run(self):
222222
karate = nx.karate_club_graph()

brainx/weighted_modularity.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ class LouvainCommunityDetection(object):
195195
minimum threshold value for change in modularity
196196
default(0.0000001)
197197
198+
Methods
199+
-------
200+
run()
201+
run the algorithm to find partitions at multiple levels
202+
198203
Examples
199204
--------
200205
>>> louvain = LouvainCommunityDetection(graph)
@@ -211,17 +216,30 @@ class LouvainCommunityDetection(object):
211216
"""
212217

213218
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)"""
214222
self.graph = graph
215223
self.initial_communities = communities
216224
self.minthr = minthr
217225

218226
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)
221239
return [WeightedPartition(self.graph, part) for part in partitions]
222240

223241

224-
def gen_dendogram(self):
242+
def _gen_dendogram(self):
225243
"""generate dendogram based on muti-levels of partitioning
226244
"""
227245
if type(self.graph) != nx.Graph :
@@ -336,7 +354,7 @@ def _move_node(part, node, new_comm):
336354
new_community = [x for x in new_community if len(x) > 0]
337355
return WeightedPartition(part.graph, new_community)
338356

339-
def partitions_from_dendogram(self, dendo):
357+
def _partitions_from_dendogram(self, dendo):
340358
""" returns community partitions based on results in dendogram
341359
"""
342360
all_partitions = []

0 commit comments

Comments
 (0)