Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
digitaldust opened this issue Aug 6, 2018 · 8 comments
Open

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

digitaldust opened this issue Aug 6, 2018 · 8 comments

Comments

@digitaldust
Copy link

digitaldust commented Aug 6, 2018

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
Copy link
Member

qiemem commented Aug 7, 2018

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
Copy link
Author

@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...

@NetLogo NetLogo deleted a comment from baohanyuanli Aug 7, 2018
@qiemem qiemem closed this as completed in 6df7841 Aug 7, 2018
@digitaldust
Copy link
Author

@qiemem closed because solved?

@qiemem
Copy link
Member

qiemem commented Aug 7, 2018

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
Copy link
Author

@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
Copy link
Member

qiemem commented Aug 8, 2018

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

@digitaldust
Copy link
Author

@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
Copy link
Member

qiemem commented Aug 9, 2018

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.

@qiemem qiemem reopened this Aug 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants