Skip to content

Commit 18a5708

Browse files
author
Katelyn Begany
committed
RF: Remove random_mod_old method and refs to module_merge method
1 parent 3416c66 commit 18a5708

File tree

1 file changed

+2
-65
lines changed

1 file changed

+2
-65
lines changed

brainx/modularity.py

Lines changed: 2 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,6 @@ def random_mod(self):
516516

517517
if coin_flip > 0.5:
518518
#merge
519-
#return self.module_merge(m1,m2)
520519
return self.compute_module_merge(m1,m2)
521520
else:
522521
#split
@@ -537,7 +536,7 @@ def random_mod(self):
537536
return self.compute_module_split(m1,n1,n2)
538537

539538
def determine_node_split(self,m1):
540-
""" Determine hwo to split notes within a module
539+
""" Determine how to split nodes within a module
541540
"""
542541

543542
# list of nodes within that module
@@ -553,68 +552,6 @@ def determine_node_split(self,m1):
553552

554553
return n1,n2
555554

556-
557-
def random_mod_old(self):
558-
"""Makes a choice whether to merge or split modules in a partition
559-
560-
Returns:
561-
-------
562-
if splitting: m1, n1, n2
563-
m1: the module to split
564-
n1: the set of nodes to put in the first output module
565-
n2: the set of nodes to put in the second output module
566-
567-
if merging: m1, m2
568-
m1: module 1 to merge
569-
m2: module 2 to merge
570-
"""
571-
572-
# number of modules in the partition
573-
num_mods=len(self)
574-
575-
576-
# Make a random choice bounded between 0 and 1, less than 0.5 means we will split the modules
577-
# greater than 0.5 means we will merge the modules.
578-
579-
if num_mods >= self.num_nodes-1:
580-
coin_flip = 1 #always merge if each node is in a separate module
581-
elif num_mods <= 2:
582-
coin_flip = 0 #always split if there's only one module
583-
else:
584-
coin_flip = random.random()
585-
586-
#randomly select two modules to operate on
587-
rand_mods = np.random.permutation(range(num_mods))
588-
m1 = rand_mods[0]
589-
m2 = rand_mods[1]
590-
591-
if coin_flip > 0.5:
592-
#merge
593-
#return self.module_merge(m1,m2)
594-
return self.module_merge(m1,m2)
595-
else:
596-
#split
597-
# cannot have a module with less than 1 node
598-
while len(self.index[m1]) <= 1:
599-
600-
#reselect the first module
601-
rand_mods = np.random.permutation(range(num_mods))
602-
m1 = rand_mods[0]
603-
#m1 = random.randint(0,num_mods)
604-
605-
# list of nodes within that module
606-
list_nods = list(self.index[m1])
607-
608-
# randomly partition the list of nodes into 2
609-
nod_split_ind = random.randint(1,len(list_nods)) #can't pick the first node as the division
610-
n1 = set(list_nods[:nod_split_ind])
611-
n2 = set(list_nods[nod_split_ind:])
612-
613-
#We may want to return output of merging/splitting directly, but
614-
#for now we're returning inputs for those modules.
615-
616-
return self.module_split(m1,n1,n2)
617-
618555
def random_node(self):
619556
""" Randomly reassign one node from one module to another
620557
@@ -672,7 +609,7 @@ def check_integrity(self, partition):
672609

673610
# Raise error if any partition contains NaN value(s)
674611
if [np.isnan(value) for sets in partition.values() for value in sets]:
675-
raise ValueError("Partition contains NaN(s)")
612+
raise ValueError("Partition contains NaN value(s)")
676613

677614
#-----------------------------------------------------------------------------
678615
# Functions

0 commit comments

Comments
 (0)