igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Reproducibly computing Kamada-Kawai layout?


From: Tamas Nepusz
Subject: Re: [igraph] Reproducibly computing Kamada-Kawai layout?
Date: Mon, 20 Jul 2015 18:49:51 +0200
User-agent: Mutt/1.5.23 (2014-03-12)

> I tried specifying the seed parameter as follows:
> 
>     s = []
>     s.append(range(len(g.vs)))
>     s.append(range(len(g.vs)))
>     l = g.layout_kamada_kawai(seed = s)
> 
> but the layout is still different each time.
On my machine, I get the following exception when running your code:

InternalError: Error at ../../src/layout_kk.c:99: Invalid start position matrix
size in Kamada-Kawai layout, Invalid value

This is because the layout function requires the transposed format where you
have two columns and N rows.

Another problem is that you need to provide not only the same seed matrix but
also the same seed to the random number generator to make the layout fully
deterministic. When you use the Python interface of igraph, igraph itself
relies on the built-in RNG of Python, so you can either do this:

import random
random.seed(12345)
l1 = g.layout_kamada_kawai(seed=s)
random.seed(12345)
l2 = g.layout_kamada_kawai(seed=s)

or simply get the state of the RNG before creating the layout and then restore
it:

state = random.getstate()
l1 = g.layout_kamada_kawai(seed=s)
random.setstate(state)
l2 = g.layout_kamada_kawai(seed=s)

I hope this helps; let me know if it doesn't work for you.

All the best,
T.



reply via email to

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