1
- #Author: Maxwell Bertolero
1
+
2
2
3
3
import numpy as np
4
4
from random import choice
5
5
import networkx as nx
6
6
7
- def within_community_degree (weighted_partition ):
7
+ def within_community_degree (weighted_partition , inf = 0.0 , catch_edgeless_node = True ):
8
8
'''
9
9
Computes the "within-module degree" (z-score) for each node (Guimera et al. 2005)
10
10
@@ -27,12 +27,20 @@ def within_community_degree(weighted_partition):
27
27
community_degrees .append (weighted_partition .node_degree_by_community (node )[c ])
28
28
for node in community :
29
29
within_community_degree = weighted_partition .node_degree_by_community (node )[c ]
30
+ if within_community_degree > 3 or within_community_degree < - 3 :
31
+ wc_dict [node ] = inf
32
+ continue
33
+ if node_degree == 0.0 :
34
+ if catch_edgeless_node :
35
+ raise ValueError ("Node {} is edgeless" .format (node ))
36
+ wc_dict [node ] = 0.0
37
+ continue
30
38
std = np .std (community_degrees ) # std of community's degrees
31
39
mean = np .mean (community_degrees ) # mean of community's degrees
32
40
wc_dict [node ] = (within_community_degree - mean / std ) #zscore
33
41
return wc_dict
34
42
35
- def participation_coefficient (weighted_partition , catch_edgeless_node = True ):
43
+ def participation_coefficient (weighted_partition , catch_edgeless_node = True , nan = 0.0 ):
36
44
'''
37
45
Computes the participation coefficient for each node (Guimera et al. 2005).
38
46
@@ -60,6 +68,9 @@ def participation_coefficient(weighted_partition, catch_edgeless_node=True):
60
68
node_comm = weighted_partition .get_node_community (node )
61
69
deg_per_comm .pop (node_comm )
62
70
bc_degree = sum (deg_per_comm ) #between community degree
71
+ if bc_degree == np .nan ():
72
+ pc_dict [node ] == nan
73
+ continue
63
74
if bc_degree == 0.0 :
64
75
pc_dict [node ] = 0.0
65
76
continue
0 commit comments