Skip to content

Commit 0d34091

Browse files
author
mb3152
committed
cleaned up nodal_roles within community degree, runs fast
1 parent e54057b commit 0d34091

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

brainx/nodal_roles.py

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,19 @@ def within_community_degree(weighted_partition):
1919
Dictionary of the within-module degree of each node.
2020
2121
'''
22-
all_community_degrees = {}
2322
wc_dict = {}
24-
for node in weighted_partition.graph:
25-
node_community = weighted_partition.get_node_community(node)
26-
within_community_degree = weighted_partition.degree_within_community(node)
27-
try: # to load average within module degree of community
28-
community_degrees = all_community_degrees[node_community]
29-
except: # collect within module degree of community
30-
community_degrees = []
31-
for node in node_community:
32-
partition.degree_within_community(node)
33-
community_degrees.append()
34-
all_community_degrees[node_community] = community_degrees
35-
# I don't know if it's faster to compute this on the fly every
36-
# time or store the results in a dictionary?
37-
std = np.std(community_degrees) # std of community's degrees
38-
mean = np.mean(community_degrees) # mean of community's degrees
39-
# z-score
40-
wc_dict[node] = (within_community_degree - mean / std)
23+
for c, community in enumerate(weighted_partition.communities):
24+
community_degrees = []
25+
# community = list(community)
26+
for node in community: #get average within-community-degree
27+
community_degrees.append(weighted_partition.node_degree_by_community(node)[c])
28+
for node in community:
29+
within_community_degree = weighted_partition.node_degree_by_community(node)[c]
30+
std = np.std(community_degrees) # std of community's degrees
31+
mean = np.mean(community_degrees) # mean of community's degrees
32+
wc_dict[node] = (within_community_degree - mean / std) #zscore
4133
return wc_dict
4234

43-
4435
def participation_coefficient(weighted_partition, catch_edgeless_node=True):
4536
'''
4637
Computes the participation coefficient for each node (Guimera et al. 2005).

0 commit comments

Comments
 (0)