@@ -121,7 +121,26 @@ def total_links(part):
121
121
weights [node_comm ]+= weight
122
122
return weights
123
123
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
124
142
143
+
125
144
def meta_graph (partition ):
126
145
""" takes partition communities and creates a new meta graph where
127
146
communities are now the nodes, the new edges are created based on the
@@ -177,24 +196,7 @@ def _community_nodes_alledgesw(part, removed_node):
177
196
178
197
179
198
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
+
198
200
199
201
def node_degree (graph , node ):
200
202
""" find the summed weight to node
0 commit comments