igraph-help
[Top][All Lists]

## Re: [igraph] Betweenness centralization in python snippet

 From: Tamás Nepusz Subject: Re: [igraph] Betweenness centralization in python snippet Date: Sat, 26 Feb 2011 15:31:16 +0100

```Thanks Bernie, this is much appeciated.

I've added this to the igraph wiki at http://igraph.wikidot.com/python-recipes.
The only modification I'd suggest is to calculate max(temparr) in advance and
not inside sum(), otherwise it will be calculated once for every element of
temparr.

--
Tamas

On 24 Feb 2011, at 20:06, Bernie Hogan wrote:

> Hi all,
>
> I'm not sure if this has been posted before (I'm filtering a lot of
> mail these days), but based on the R recipe I've coded up betweenness
> centralization in the python version of igraph. I tested the result
> against the most recent Pajek, and its the same to as many digits as
> Pajek displays (3 significant digits). Enjoy. Its clearly not robust -
> so if you have a graph with less than 3 nodes or all isolates you
> might get funny results.
>
> def betweenness_centralization(G):
>       vnum = G.vcount()
>       denom = ((vnum-1)*(vnum-2))
>
>       temparr = [2*i/denom for i in G.betweenness()]
>       result = sum([max(temparr)-i for i in temparr])/(vnum-1)
>
>       return result
>
> G = Graph()
> #....
> print betweenness_centralization(G)
>
> Take care,
> BERNiE
> Dr Bernie Hogan
> Research Fellow, Oxford Internet Institute
> University of Oxford
> http://www.oii.ox.ac.uk/people/?id=140
>
> _______________________________________________
> igraph-help mailing list