@@ -95,6 +95,7 @@ def __init__(self, graph, index):
95
95
# Store the nodes as a set of contiguous integers (indices into
96
96
#the adjacency_matrix), needed for many operations
97
97
self ._node_set = set (range (self .num_nodes ))
98
+ self ._node_names = graph .nodes ()
98
99
## raise useful error if index is missing nodes in graph
99
100
self ._check_allnodes_in_index (graph )
100
101
@@ -510,8 +511,9 @@ def random_mod(self):
510
511
num_mods = len (self )
511
512
512
513
513
- # Make a random choice bounded between 0 and 1, less than 0.5 means we will split the modules
514
- # greater than 0.5 means we will merge the modules.
514
+ # Make a random choice bounded between 0 and 1,
515
+ # less than 0.5 means we will split the modules
516
+ # greater than 0.5 means we will merge the modules.
515
517
516
518
if num_mods >= self .num_nodes - 1 : ### CG: why are we subtracting 1 here?
517
519
coin_flip = 1 #always merge if each node is in a separate module
@@ -611,6 +613,15 @@ def store_best(self):
611
613
#Store references to the original graph and label dict
612
614
self .bestindex = copy .deepcopy (self .index )
613
615
616
+ def index_as_node_names (self ):
617
+ """ index by default contains references to integers represented the
618
+ nodes as indexed in the adjacency matrix defined in the original graph.
619
+ This will return the index (partition) using the graph node names"""
620
+ named_part = []
621
+ for nmod , part in self .index .iteritems ():
622
+ named_part .append ([self ._node_names [x ] for x in part ])
623
+ return named_part
624
+
614
625
def check_integrity (self , partition ):
615
626
""" Raises error if partition structure contains
616
627
empty partitions or Nan values"""
0 commit comments