Skip to content

Commit ef94399

Browse files
author
mb3152
committed
cleaned up nodal_roles,added option for nans or infinity numbers
1 parent 0d34091 commit ef94399

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

brainx/nodal_roles.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#Author: Maxwell Bertolero
1+
#Author: Maxwell Bertolero, [email protected], [email protected]
22

33
import numpy as np
44
from random import choice
55
import networkx as nx
66

7-
def within_community_degree(weighted_partition):
7+
def within_community_degree(weighted_partition, inf = 0.0, catch_edgeless_node=True):
88
'''
99
Computes the "within-module degree" (z-score) for each node (Guimera et al. 2005)
1010
@@ -27,12 +27,20 @@ def within_community_degree(weighted_partition):
2727
community_degrees.append(weighted_partition.node_degree_by_community(node)[c])
2828
for node in community:
2929
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
3038
std = np.std(community_degrees) # std of community's degrees
3139
mean = np.mean(community_degrees) # mean of community's degrees
3240
wc_dict[node] = (within_community_degree - mean / std) #zscore
3341
return wc_dict
3442

35-
def participation_coefficient(weighted_partition, catch_edgeless_node=True):
43+
def participation_coefficient(weighted_partition, catch_edgeless_node=True, nan=0.0):
3644
'''
3745
Computes the participation coefficient for each node (Guimera et al. 2005).
3846
@@ -60,6 +68,9 @@ def participation_coefficient(weighted_partition, catch_edgeless_node=True):
6068
node_comm = weighted_partition.get_node_community(node)
6169
deg_per_comm.pop(node_comm)
6270
bc_degree = sum(deg_per_comm) #between community degree
71+
if bc_degree == np.nan():
72+
pc_dict[node] == nan
73+
continue
6374
if bc_degree == 0.0:
6475
pc_dict[node] = 0.0
6576
continue

0 commit comments

Comments
 (0)