[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[igraph] Translation of R commands into Python
From: |
Lorenzo Isella |
Subject: |
[igraph] Translation of R commands into Python |
Date: |
Wed, 24 Jun 2009 16:37:15 +0200 |
User-agent: |
Thunderbird 2.0.0.21 (X11/20090409) |
Dear All,
Some time ago I posted a small R script with a basic analysis of a real
graph. I am trying to do the same with Python, but I am experiencing
some problems, mainly due to the fact that I am not at ease with the
automatically generated documentation of the Python module and I have
not been able to find much online (have I looked in the wrong places?).
Below you can find a list of igraph commands under R (mainly taken from
that previous email of mine). Apart from reading the graph from a
two-column matrix, all the other commands simply assume that there is a
graph g.
What I would really like to see is how these commands for the igraph R
bindings translate into commands for the Python bindings.
Many thanks
Lorenzo
# Now I have the graph as a two-column matrix
g <- graph(t(graph_input_unweighted), directed=FALSE)
g <- simplify(g)
#degree of each vertex
dd <- degree(g)
pfit <- power.law.fit(dd)
#Now calculate graph diameter
d <- get.diameter(g)
#Now calculate the vertex betweenness
#and find the node with the highest betweenness
ver_bet <- betweenness(g)
#Now calculate the clustering coefficients (also called transitivity of
a graph)
clust <- transitivity(g, type="local")
# calculate average nearest-neighbour degree
knn <- graph.knn(g)
#knn$knnk lists the average nearest neighbour degree for vertices having
at least one neighbour
#Now get the shortest paths in the network
mean_shortest_path <- average.path.length(g)
#Now consider the neighbourhood of the graph (the final purpose is to
calculate
# the average number of nodes within a distance x from a general node in
the graph )
#I know the graph diameter, i.e. the longest shortest path. Since d
stores actually
# the nodes in the graph diameter, the length of the diameter (number of
edges)
# is actually length(d)-1
M_l <- seq(length(d)-1)
for (i in seq(length(d)-1)){
M_l[i] <- mean(neighborhood.size(g, i, nodes=V(g)))
}
- [igraph] Translation of R commands into Python,
Lorenzo Isella <=