@@ -19,28 +19,19 @@ def within_community_degree(weighted_partition):
19
19
Dictionary of the within-module degree of each node.
20
20
21
21
'''
22
- all_community_degrees = {}
23
22
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
41
33
return wc_dict
42
34
43
-
44
35
def participation_coefficient (weighted_partition , catch_edgeless_node = True ):
45
36
'''
46
37
Computes the participation coefficient for each node (Guimera et al. 2005).
0 commit comments