[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [igraph] Leverage centrality implementation in igraph
From: |
Tamás Nepusz |
Subject: |
Re: [igraph] Leverage centrality implementation in igraph |
Date: |
Thu, 26 Jul 2012 18:03:13 +0200 |
Hi,
Here is an R implementation -- this is just a quick one-shot solution and not a
function, mostly because I'm not that experienced in R and there might be a
better solution anyway.
So, first, get the degrees and the number of nodes:
k <- degree(g)
n <- vcount(g)
Then the magic happens here:
sapply(1:n, function(v) { mean((k[v]-k[neighbors(g,v)]) /
(k[v]+k[neighbors(g,v)])) })
Basically, we have an inner function here that calculates the leverage
centrality for a single vertex, and sapply() simply applies it to every vertex
index between 1 and n, inclusive. The function will return NA for isolated
vertices.
--
T.
On Thursday, 26 July 2012 at 13:37, Alex Upton wrote:
>
> Hi all,
>
>
> Thank you for your help and suggestions. I am using igraph in R, and have
> tried translating the code for leverage centrality kindly suggested by Tamás
> from Python to R. However, I am getting errors with this, so if it is not too
> much trouble, could someone suggest an R implementation of the following code:
>
>
> def leverage_centrality(graph):
> k = graph.degree()
> n = graph.vcount()
> result = []
> for i in xrange(n):
> ki = k[i]
> if ki == 0:
> result.append(0.0)
> else:
> result.append(sum((ki-k[j])/(ki+k[j]) for j in graph.neighbors(i))
> / ki)
> return result
>
>
> Thank you for your feedback as well Bernie, I have noticed that there are a
> number of centrality metrics out there that seem to be well-suited to only
> type of application.
>
> Kind regards,
>
> Alex
>
>
> Hi Alex,
>
> As Bernie has mentioned, the measure itself is relatively simple to calculate
>
> and it does not have a significant uptake in the scientific community yet, so
> I
> don't think that a low-level C implementation of the measure will be added to
>
> igraph any time soon (unless someone is willing to provide a patch). It is
> relatively easy to calculate using either the R or the Python interface; a
> quick (untested) Python implementation is as follows:
>
> def leverage_centrality(graph):
> k = graph.degree()
> n = graph.vcount()
> result = []
> for i in xrange(n):
> ki = k[i]
> if ki == 0:
> result.append(0.0)
> else:
> result.append(sum((ki-k[j])/(ki+k[j]) for j in graph.neighbors(i))
> / ki)
> return result
>
> --
> T.
>
> --------------------------------------------------------------------------------------------
> Alex Upton, BEng, MRes, PG Cert Business Administration
>
> PhD Researcher Biomedical Informatics, Signals and Systems
> School of Electronic, Electrical and Computer Engineering,
> College of Engineering and Physical Sciences, University of Birmingham
> Edgbaston, Birmingham, B15 2TT, United Kingdom
>
> Fax: +44 121 4144291 (school general office)
> Email: address@hidden (mailto:address@hidden)
>
> Personal Web: http://postgrad.eee.bham.ac.uk/uptona/
> --------------------------------------------------------------------------------------------
> _______________________________________________
> igraph-help mailing list
> address@hidden (mailto:address@hidden)
> https://lists.nongnu.org/mailman/listinfo/igraph-help