[networkx-discuss] Edge betweenness centrality

329 views
Skip to first unread message

Francesc Segura

unread,
May 26, 2011, 12:59:28 PM5/26/11
to networkx-discuss
Hello,

I am working on a cost function that relates the betweenness
centrality of an edge and the distance between two nodes of a
grid_2d_graph. My question is if there is any way to get the edge
betwenness centrality of an edge I choose related to the two nodes it
connects.

I have tried something like:

bc = NX.edge_betweenness_centrality(G,normalized=True)
bc.values()[i]

But it has a problem, the dictonary returned by the function isn't
sorted in any regular way so the easiest way I have thought is to look
for the edge that connects the two desired nodes, because their name
is (i,j) and are easily loopable, and find its BC, but I don't find
anyway to deal with it. Another solution may be sorting the
dictionary in some way that the loop fits in but this may be
difficult. Do you have any suggestion to solve this problem?

Thanks a lot

Aric Hagberg

unread,
May 26, 2011, 1:16:11 PM5/26/11
to networkx...@googlegroups.com

You can lookup up the value for any edge directly in the dictionary.
e.g.

In [1]: import networkx as nx

In [2]: G=nx.path_graph(4)

In [3]: e=nx.edge_betweenness_centrality(G,normalized=True)

In [4]: e
Out[4]: {(0, 1): 3.0, (1, 2): 4.0, (2, 3): 3.0}

In [5]: e[(0,1)]
Out[5]: 3.0

The edges are oriented arbitrarily so e.g. in this case (0,1)appears
in the dictionary but (1,0) doesn't. You'll have to check both
orientations to get the value for a particular edge. You can do that
with (slightly cryptic)

In [6]: e.get((1,0),e.get((0,1)))
Out[6]: 3.0


Aric

Reply all
Reply to author
Forward
0 new messages