Skip to content

Commit 3bc2b4b

Browse files
author
Maxwell Bertolero
committed
Update nodal_roles.py
1 parent a905640 commit 3bc2b4b

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

brainx/nodal_roles.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def within_community_degree(weighted_partition, nan = 0.0, catch_edgeless_node=T
4646
if std == 0.0: #so we don't divide by 0
4747
wc_dict[node] = (within_community_degree - mean) #z_score
4848
continue
49-
wc_dict[node] = (within_community_degree - mean / std) #z_score
49+
wc_dict[node] = ((within_community_degree - mean) / std) #z_score
5050
return wc_dict
5151

5252
def participation_coefficient(weighted_partition, catch_edgeless_node=True):
@@ -71,20 +71,19 @@ def participation_coefficient(weighted_partition, catch_edgeless_node=True):
7171
Dictionary of the participation coefficient of each node.
7272
'''
7373
pc_dict = {}
74-
graph = weighted_partition.graph
75-
for node in graph:
74+
for node in weighted_partition.graph:
7675
node_degree = weighted_partition.node_degree(node)
7776
if node_degree == 0.0:
7877
if catch_edgeless_node:
7978
raise ValueError("Node {} is edgeless".format(node))
8079
pc_dict[node] = 0.0
8180
continue
82-
deg_per_comm = weighted_partition.node_degree_by_community(node)
83-
deg_per_comm.pop(weighted_partition.get_node_community(node))
84-
bc_degree = sum(deg_per_comm) #between community degree
85-
if bc_degree == 0.0:
86-
pc_dict[node] = 0.0
87-
continue
88-
pc = 1 - ((float(bc_degree) / float(node_degree))**2)
81+
pc = 0.0
82+
for comm_degree in weighted_partition.node_degree_by_community(node):
83+
try:
84+
pc = pc + ((comm_degree/node_degree)**2)
85+
except:
86+
continue
87+
pc = 1-pc
8988
pc_dict[node] = pc
90-
return pc_dict
89+
return pc_dict

0 commit comments

Comments
 (0)