11#Author: Maxwell Bertolero, bertolero@berkeley.edu, mbertolero@gmail.com
2+ #Author: Maxwell Bertolero, bertolero@berkeley.edu, mbertolero@gmail.com
23
34import numpy as np
45from random import choice
@@ -46,7 +47,7 @@ def within_community_degree(weighted_partition, nan = 0.0, catch_edgeless_node=T
4647 if std == 0.0 : #so we don't divide by 0
4748 wc_dict [node ] = (within_community_degree - mean ) #z_score
4849 continue
49- wc_dict [node ] = (within_community_degree - mean / std ) #z_score
50+ wc_dict [node ] = (( within_community_degree - mean ) / std ) #z_score
5051 return wc_dict
5152
5253def participation_coefficient (weighted_partition , catch_edgeless_node = True ):
@@ -71,20 +72,19 @@ def participation_coefficient(weighted_partition, catch_edgeless_node=True):
7172 Dictionary of the participation coefficient of each node.
7273 '''
7374 pc_dict = {}
74- graph = weighted_partition .graph
75- for node in graph :
75+ for node in weighted_partition .graph :
7676 node_degree = weighted_partition .node_degree (node )
7777 if node_degree == 0.0 :
7878 if catch_edgeless_node :
7979 raise ValueError ("Node {} is edgeless" .format (node ))
8080 pc_dict [node ] = 0.0
8181 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 )
82+ pc = 0.0
83+ for comm_degree in weighted_partition .node_degree_by_community (node ):
84+ try :
85+ pc = pc + (( comm_degree / node_degree ) ** 2 )
86+ except :
87+ continue
88+ pc = 1 - pc
8989 pc_dict [node ] = pc
90- return pc_dict
90+ return pc_dict
0 commit comments