Skip to content

Commit ddb8ebc

Browse files
committed
Start to clean up nodal_summaryOut.
1 parent f92f5aa commit ddb8ebc

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

brainx/metrics.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,28 +271,36 @@ def graph_summary(G):
271271
return dict( lp=lp.mean(), clust=clust.mean(), glob_eff=glob_eff.mean(),
272272
loc_eff=loc_eff.mean() )
273273

274+
274275
def nodal_summaryOut(G, n_nodes):
275-
""" Compute statistics for individual nodes
276+
"""Compute statistics for individual nodes.
276277
277278
Parameters
278279
----------
279-
G: graph data output from mkgraph
280-
out: array output from nodal_summaryOut, so can keep appending
281-
cost: cost value for these calculations
282-
n_nodes: number of nodes in graph.
280+
G: networkx graph
281+
An undirected graph.
282+
283+
n_nodes: integer
284+
Number of nodes in G.
283285
284286
Returns
285287
-------
288+
dictionary
289+
The keys of this dictionary are lp (which refers to path
290+
length), clust (clustering coefficient), b_cen (betweenness
291+
centrality), c_cen (closeness centrality), nod_eff (nodal
292+
efficiency), loc_eff (local efficiency), and deg (degree). The
293+
values are lists of metrics, in ascending order of node labels.
286294
287-
A dict with: lp, clust, b_cen, c_cen, nod_eff, loc_eff, degree."""
288-
289-
lp = nodal_pathlengths(G,n_nodes) #can't use the regular one, because it substitutes [] for disconnected nodes
295+
"""
296+
# nodal_pathlengths is needed because NetworkX's shortest_path_length
297+
# returns an empty list for disconnected nodes.
298+
lp = nodal_pathlengths(G,n_nodes)
290299
clust = np.array(nx.clustering(G).values())
291300
b_cen = np.array(nx.betweenness_centrality(G).values())
292301
c_cen = np.array(nx.closeness_centrality(G).values())
293-
nod_eff=nodal_efficiency(G)
294-
loc_eff=local_efficiency(G)
302+
nod_eff = nodal_efficiency(G)
303+
loc_eff = local_efficiency(G)
295304
deg = G.degree().values()
296-
297305
return dict(lp=lp, clust=clust, b_cen=b_cen, c_cen=c_cen, nod_eff=nod_eff,
298-
loc_eff=loc_eff,deg=deg)
306+
loc_eff=loc_eff, deg=deg)

0 commit comments

Comments
 (0)