Skip to content

Commit c1ef9da

Browse files
author
CindeeM
committed
Cleaned up and organized a bit more
1 parent 0c1e6ba commit c1ef9da

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

brainx/weighted_modularity.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,26 @@ def total_links(part):
121121
weights[node_comm]+= weight
122122
return weights
123123

124+
def internal_links(part):
125+
""" sum of weighted links strictly inside each community
126+
includes self loops"""
127+
comm = part.community
128+
weights = [0] * len(comm)
129+
comm = part.community
130+
for val, nodeset in enumerate(comm):
131+
for node in nodeset:
132+
nodes_within = set([x for x in part.graph[node].keys() \
133+
if x in nodeset])
134+
if len(nodes_within) < 1:
135+
continue
136+
if node in nodes_within:
137+
weights[val]+= part.graph[node][node]['weight']
138+
nodes_within.remove(node)
139+
weights[val] += np.sum(part.graph[node][x]['weight']/ 2. \
140+
for x in nodes_within)
141+
return weights
124142

143+
125144
def meta_graph(partition):
126145
""" takes partition communities and creates a new meta graph where
127146
communities are now the nodes, the new edges are created based on the
@@ -177,24 +196,7 @@ def _community_nodes_alledgesw(part, removed_node):
177196

178197

179198

180-
def internal_links(part):
181-
""" sum of weighted links strictly inside each community
182-
includes self loops"""
183-
comm = part.community
184-
weights = [0] * len(comm)
185-
comm = part.community
186-
for val, nodeset in enumerate(comm):
187-
for node in nodeset:
188-
nodes_within = set([x for x in part.graph[node].keys() \
189-
if x in nodeset])
190-
if len(nodes_within) < 1:
191-
continue
192-
if node in nodes_within:
193-
weights[val]+= part.graph[node][node]['weight']
194-
nodes_within.remove(node)
195-
weights[val] += np.sum(part.graph[node][x]['weight']/ 2. \
196-
for x in nodes_within)
197-
return weights
199+
198200

199201
def node_degree(graph, node):
200202
""" find the summed weight to node

0 commit comments

Comments
 (0)