igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] average path length for graphs containing multiple componen


From: Giovanni Marco Dall'Olio
Subject: Re: [igraph] average path length for graphs containing multiple components
Date: Wed, 21 Nov 2012 14:42:12 +0100

Thank you!

It's nice to know that the function "get_shortest_paths" support weights. So, the formula should be something like the following:

   av_path_length = mean([pl for pl in sum(g.shortest_paths(weights=g.vs['weight']), []) if pl > 0 and pl != float('inf')])

I have update the gist, in case anybody is interested: https://gist.github.com/4124710

Thank you again, I have been a bit stuck on this in the last few days :-)





On Wed, Nov 21, 2012 at 2:13 PM, Tamás Nepusz <address@hidden> wrote:
> Hi, I solved this by myself..
Great! :) Now, if you want to generalize it to weighted graphs, there are at least two possible ways: either you calculate the average weight of the shortest paths or you still calculate the average path length but take the weights into account when you calculate what the shortest path is. Both are relatively easy to implement if you use the output of get_shortest_paths() or shortest_paths() since they both support weights.

Best,
Tamas




--
Giovanni Dall'Olio, phd student
IBE, Institut de Biologia Evolutiva, CEXS-UPF (Barcelona, Spain)

My blog on bioinformatics: http://bioinfoblog.it


reply via email to

[Prev in Thread] Current Thread [Next in Thread]