NetLogo / NW-Extension

This is the NetLogo Network Extension. For general information about NetLogo, see:
http://ccl.northwestern.edu/netlogo/
Other
62 stars 25 forks source link

nw:load-graphml somehow messes with the random seed #187

Open digitaldust opened 6 years ago

digitaldust commented 6 years ago

I think there is a problem with random seed if nw:load-graphml is invoked.

If you create a network like this, you can set the random seed and every time you call the procedure you have a network in the same exact position:

to setup
  ca
  random-seed 1
  create-turtles 100
  ask turtles [
    ask other turtles [
      if random-float 1 < 0.01 [
        create-link-with myself
      ]
    ]
  ]
  repeat 10 [layout-spring turtles links 0.2 5 1]
  nw:set-context turtles links
end

same applies if you create the network from scratch using the nw extension:

to setup2
  ca
  random-seed 1
  nw:generate-random turtles links 100 0.01
  repeat 10 [layout-spring turtles links 0.2 5 1]
  nw:set-context turtles links
end

however, if you try to load from a graphml file, every time you have the network with a different layout - and this applies with a graphml that I have generated as well as the graphml file used in the nw guide:

to setup3
  ca
  random-seed 1
  nw:load-graphml "random-exact-50-4-106.graphml"
  repeat 10 [layout-spring turtles links 0.2 5 1]
end
to setup4
  ca
  random-seed 1
  nw:load-graphml "prova.graphml"
  repeat 10 [layout-spring turtles links 0.2 5 1]
end

See also the discussion here to find a netlogo model and graphml files that demonstrate the issue.

qiemem commented 6 years ago

Thanks for reporting! I've managed to reproduce it, but it seems to be some sort of interaction between nw:load-graphml and layout-spring. On its, nw:load-graphml affects the RNG as expected. Still diagnosing, but will hopefully have it fixed for the next version.

digitaldust commented 6 years ago

@qiemem I am not sure the layout is responsible, even if you comment it out and do like:

to setup3 ca random-seed 1 nw:load-graphml "random-exact-50-4-106.graphml" ;repeat 10 [layout-spring turtles links 0.2 5 1] nw:set-context turtles links ask turtles [setxy random-xcor random-ycor] end

you can clearly see that things are not fixed as per the seed, but changes every time you call setup3. This does not happen if you import the data as a csv file for instance, so I really think load-graphml is wrong in some way...

digitaldust commented 6 years ago

@qiemem closed because solved?

qiemem commented 6 years ago

Yup! It was importing the nodes in a non-deterministic order, so which agent id got matched up with which node was different each import. So, it wasn't actually messing with the RNG, but resulted in similar symptoms.

digitaldust commented 6 years ago

@qiemem that’s great! Is there any chance to access a fixed version of nw? Sorry for the newbie question, I really need to run some experiments but I am not really confident with the git workflow in these cases...

qiemem commented 6 years ago

Sure. Here you go: https://www.dropbox.com/s/ugxxt7fhvqah3wm/nw.zip

digitaldust commented 6 years ago

@qiemem thanks a ton, I see the patch works if I just read the graphml file in... still if you call layout-radial after importing then the ordering is not preserved, so maybe also layout-radial is doing the same stuff? anyway thanks a ton for now, I can run my experiment and have reproducible results now... 👍

qiemem commented 6 years ago

I fixed the problem of deterministic turtle creation, but apparently link creation order is still non-deterministic. Depending on your application, this may or may not affect results. I should be able to fix this additional problem in the next few days.