igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Translate code from r to python


From: simone gabbriellini
Subject: Re: [igraph] Translate code from r to python
Date: Sun, 28 Jun 2009 20:54:54 +0200

Hi Tamas,

your code gives me an error:

TypeError: argument 1 must be list, not int
WARNING: Failure executing file: <analisi_venezia.py>

is this a correct solution?

g_sw = Graph.Lattice([1, g.vcount()], nei=sum(g.degree())/g.vcount(), dir=True, mutual=True)

If I understand the rewire procedure correctly, it changes in this case the 25% of the edges in the graph. How can it be that the average path after the rewire is longer than in the regular lattice??? This is what I have:

In [4]: g = Graph.Read_GraphML("200403.graphml")

In [5]: print g.summary()
37 nodes, 728 edges, directed

Number of components: 2
Diameter: 4
Density: 0.5465
Reciprocity: 0.9259
Average path length: 1.4754

In [6]: gSW = Graph.Lattice([1, g.vcount()], nei=sum(g.degree())/ g.vcount(), directed=True, mutual=True)

In [7]: print gSW.summary()
37 nodes, 740 edges, directed

Number of components: 1
Diameter: 3
Density: 0.5556
Reciprocity: 0.0556
Average path length: 1.8686

In [8]: gSW.rewire(0.25*gSW.ecount())
/Library/Frameworks/Python.framework/Versions/4.1.30101/bin/ipython:1: DeprecationWarning: integer argument expected, got float #!/Library/Frameworks/Python.framework/Versions/4.1.30101/Resources/ Python.app/Contents/MacOS/Python
Out[8]: <igraph.Graph object at 0x1570d470>

In [9]: print gSW.summary()
37 nodes, 740 edges, directed

Number of components: 1
Diameter: 14
Density: 0.5556
Reciprocity: 0.0571
Average path length: 3.7523

maybe this is an expected behaviour, or maybe I am doing something wrong...

best regards,
Simone


Il giorno 26/giu/09, alle ore 13:19, Tamas Nepusz ha scritto:

g.sw=rewire.edges(graph.lattice(vcount(g), nei=mean(degree(g)), dir=TRUE, mutual=TRUE), p=0.25)
g_sw = Graph.Lattice(g.vcount(), nei=sum(g.degree())/g.vcount(), dir=True, mutual=True)
g_sw.rewire(0.25 * g_sw.ecount())

Note that rewire() does not have a p= argument in Python, only n=... which lets you specify the number of rewirings. That's why I've written g_sw.ecount() * 0.25. Another difference is that Graph.rewire() rewires the graph in-place in Python, so you must construct the graph first and then invoke its rewire() method.

--
T.



_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help





reply via email to

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