@@ -336,6 +336,36 @@ def partitions_from_dendogram(dendo):
336
336
all_partitions .append (init_part )
337
337
return all_partitions
338
338
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
339
369
340
370
341
371
def meta_graph (partition ):
@@ -363,36 +393,6 @@ def meta_graph(partition):
363
393
364
394
return metagraph , mapping
365
395
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
396
396
397
397
398
398
0 commit comments