Skip to content

Commit c47314c

Browse files
author
CindeeM
committed
Move _combine to LouvainPArtition class, FIXME breaks tests
1 parent b51f094 commit c47314c

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

brainx/weighted_modularity.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,36 @@ def partitions_from_dendogram(dendo):
336336
all_partitions.append(init_part)
337337
return all_partitions
338338

339+
def _combine(prev, next):
340+
"""combines nodes in sets (prev) based on mapping defined by
341+
(next) (which now treats a previous communitity as a node)
342+
but maintains specification of all original nodes
343+
344+
Parameters
345+
----------
346+
prev : list of sets
347+
communities partition
348+
next : list of sets
349+
next level communities partition
350+
351+
Examples
352+
--------
353+
>>> prev = [set([0,1,2]), set([3,4]), set([5,6])]
354+
>>> next = [set([0,1]), set([2])]
355+
>>> result = _combine(prev, next)
356+
[set([0, 1, 2, 3, 4]), set([5,6])]
357+
"""
358+
expected_len = np.max([x for sublist in next for x in sublist])
359+
if not len(prev) == expected_len + 1:
360+
raise ValueError('Number of nodes in next does not'\
361+
' match number of communities in prev')
362+
ret = []
363+
for itemset in next:
364+
newset = set()
365+
for tmps in itemset:
366+
newset.update(prev[tmps])
367+
ret.append(newset)
368+
return ret
339369

340370

341371
def meta_graph(partition):
@@ -363,36 +393,6 @@ def meta_graph(partition):
363393

364394
return metagraph, mapping
365395

366-
def _combine(prev, next):
367-
"""combines nodes in sets (prev) based on mapping defined by
368-
(next) (which now treats a previous communitity as a node)
369-
but maintains specification of all original nodes
370-
371-
Parameters
372-
----------
373-
prev : list of sets
374-
communities partition
375-
next : list of sets
376-
next level communities partition
377-
378-
Examples
379-
--------
380-
>>> prev = [set([0,1,2]), set([3,4]), set([5,6])]
381-
>>> next = [set([0,1]), set([2])]
382-
>>> result = _combine(prev, next)
383-
[set([0, 1, 2, 3, 4]), set([5,6])]
384-
"""
385-
expected_len = np.max([x for sublist in next for x in sublist])
386-
if not len(prev) == expected_len + 1:
387-
raise ValueError('Number of nodes in next does not'\
388-
' match number of communities in prev')
389-
ret = []
390-
for itemset in next:
391-
newset = set()
392-
for tmps in itemset:
393-
newset.update(prev[tmps])
394-
ret.append(newset)
395-
return ret
396396

397397

398398

0 commit comments

Comments
 (0)