Skip to content

Commit ada22bd

Browse files
author
whitergh
committed
Merge pull request #24 from mb3152/master
Update nodal_roles.py
2 parents b37cec7 + 0dabfbc commit ada22bd

20 files changed

+6463
-11
lines changed

brainx/nodal_roles.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#Author: Maxwell Bertolero, [email protected], [email protected]
2+
#Author: Maxwell Bertolero, [email protected], [email protected]
23

34
import numpy as np
45
from 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

5253
def 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

build/lib/brainx/__init__.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
"""Top-level init file for brainx package.
2+
"""
3+
4+
def patch_nx():
5+
"""Temporary fix for NX's watts_strogatz routine, which has a bug in versions 1.1-1.3
6+
"""
7+
8+
import networkx as nx
9+
10+
# Quick test to see if we get the broken version
11+
g = nx.watts_strogatz_graph(2, 0, 0)
12+
13+
if g.number_of_nodes() != 2:
14+
# Buggy version detected. Create a patched version and apply it to nx
15+
16+
nx._watts_strogatz_graph_ori = nx.watts_strogatz_graph
17+
18+
def patched_ws(n, k, p, seed=None):
19+
if k<2:
20+
g = nx.Graph()
21+
g.add_nodes_from(range(n))
22+
return g
23+
else:
24+
return nx._watts_strogatz_graph_ori(n, k, p, seed)
25+
26+
patched_ws.__doc__ = nx._watts_strogatz_graph_ori.__doc__
27+
28+
# Applying monkeypatch now
29+
import warnings
30+
warnings.warn("Monkeypatching NetworkX's Watts-Strogatz routine")
31+
32+
nx.watts_strogatz_graph = patched_ws
33+
34+
35+
patch_nx()

build/lib/brainx/detect_modules.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
"""DEPRECATED - use the modularity module instead."""
2+
3+
import warnings
4+
warnings.warn(__doc__, DeprecationWarning)
5+
6+
# Backwards compatibility
7+
from modularity import *

0 commit comments

Comments
 (0)