From 6212fbe9178be9985fb291737b77e29556efb09c Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Thu, 21 Jun 2018 14:55:08 +0200 Subject: [PATCH 1/2] Move `exit-condition` evaluation from BehaviorSpace to go procedure * this move should give us better ability to control the flow of the program wrt parts that should be run outside the `go-core` procedure (e.g. the `exit-condition` reporter) * what was previously the `go` procedure is now named `go-core` and called by the new `go` procedure; the interface buttons and the default BehaviorSpace experiment have been adjusted accordingly * the `exit-condition` reporter is now directly evaluated in the `go` procedure and saved in a global variable (`g-exit-condition?`) in case the go procedure is called with the argument `true` (which is what the go-stop button does) * the go-stop button can now be interrupted the same way as the go button --- README.md | 7 +++++++ SocNetABM.nlogo | 43 +++++++++++++++++++++++++++---------------- protocol.nls | 4 ++-- 3 files changed, 36 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0b59ce4..209cc6f 100644 --- a/README.md +++ b/README.md @@ -132,6 +132,13 @@ If there is a researcher for whom, if given sufficient time for her belief to co When the network is a de facto complete network, scientists might be able to utilize a more performant sharing procedure (the second condition is that they have to be converged): `share-fast`. This variable signals whether or not such a de-facto complete network is present in the current run. +#### g-exit-condition? + +* format: boolean +* example: false + +If the `exit-condition` reporter is evaluated the variable will be set to `true` in case the the exit-condition is met, `false` otherwise. Positive evaluation of the exit-condition marks the end of a run. + ### Turtles-own diff --git a/SocNetABM.nlogo b/SocNetABM.nlogo index 2080804..e501460 100644 --- a/SocNetABM.nlogo +++ b/SocNetABM.nlogo @@ -7,7 +7,7 @@ globals [th-i-signal indiff-count crit-interactions-th1 crit-interactions-th2 converge-reporters converge-reporters-values run-start-scientists-save rndseed g-confidence g-depressed-confidence g-fast-sharing-enabled g-last-convlight-th g-conv-dur-th1 g-conv-dur-th2 - g-conv-start-th1 g-conv-start-th2] + g-conv-start-th1 g-conv-start-th2 g-exit-condition?] __includes ["protocol.nls"] @@ -59,6 +59,7 @@ to setup [rs] set g-conv-dur-th2 [] set g-conv-start-th1 [] set g-conv-start-th2 [] + set g-exit-condition? false reset-ticks end @@ -67,7 +68,7 @@ end ; one go = one round -to go +to go-core ask turtles [ pull ] @@ -102,14 +103,19 @@ end - -; runs until the exit-condition is met -to go-stop - let stop? 0 - with-local-randomness [set stop? exit-condition] - while [not stop?][ - go - with-local-randomness [set stop? exit-condition] +; advances the model one round with- or without evaluating the exit-condition +; depending on the argument: +; exit? = exit-condition evaluated?, type: boolean +to go [exit?] + with-local-randomness [ + if exit? and not g-exit-condition? [ + set g-exit-condition? exit-condition + ] + ] + ifelse g-exit-condition? and exit? [ + stop + ][ + go-core ] end @@ -573,8 +579,8 @@ BUTTON 15 164 48 -NIL go +go false T 1 T @@ -660,9 +666,9 @@ BUTTON 64 124 97 -NIL go-stop -NIL +go true +T 1 T OBSERVER @@ -870,6 +876,12 @@ If there is a researcher for whom, if given sufficient time for her belief to co When the network is a de facto complete network, scientists might be able to utilize a more performant sharing procedure (the second condition is that they have to be converged): `share-fast`. This variable signals whether or not such a de-facto complete network is present in the current run. +#### g-exit-condition? + +* format: boolean +* example: false + +If the `exit-condition` reporter is evaluated the variable will be set to `true` in case the the exit-condition is met, `false` otherwise. Positive evaluation of the exit-condition marks the end of a run. ### Turtles-own @@ -1278,15 +1290,14 @@ false Polygon -7500403 true true 270 75 225 30 30 225 75 270 Polygon -7500403 true true 30 75 75 30 270 225 225 270 @#$#@#$#@ -NetLogo 6.0.2 +NetLogo 6.0.4 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ setup new-seed - go - exit-condition + go true successful-run average-jumps avg-indiff-time diff --git a/protocol.nls b/protocol.nls index 4d08ef3..b8ab0d9 100644 --- a/protocol.nls +++ b/protocol.nls @@ -329,7 +329,7 @@ end ; reports the average signal for th# at the time of final convergence ; arguments: ; - th# = theory, type: string -; - rec = recording?, type: boolean +; - rec? = recording?, type: boolean to-report average-signal [th# rec?] let identifier "avgsignal" ifelse rec? [ @@ -362,7 +362,7 @@ end ; reports the average beliefs among the researchers ; arguments: ; - th# = theory, type: string -; - rec = recording?, type: boolean +; - rec? = recording?, type: boolean to-report average-belief [th# rec?] let identifier "avgbelief" ifelse rec? [ From eac2d1eda5213f0971dcc934733df7808cda7df8 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Thu, 21 Jun 2018 15:34:10 +0200 Subject: [PATCH 2/2] `fast-sharing?` now determined with-local-randomness * `fast-sharing` has been renamed to `fast-sharing?` to reflect its boolean nature. * `fast-sharing` is now determined with-local-randomness in the `go` procedure and handed over to `go-core` as an argument. This avoids distorting the rng when evaluating this reporter. --- SocNetABM.nlogo | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/SocNetABM.nlogo b/SocNetABM.nlogo index e501460..bc7d826 100644 --- a/SocNetABM.nlogo +++ b/SocNetABM.nlogo @@ -67,17 +67,38 @@ end +; advances the model one round with- or without evaluating the exit-condition +; depending on the argument: +; exit? = exit-condition evaluated?, type: boolean +to go [exit?] + let fast-sharing? 0 + with-local-randomness [ + set fast-sharing? (g-fast-sharing-enabled and converged-light) + if exit? and not g-exit-condition? [ + set g-exit-condition? exit-condition + ] + ] + ifelse g-exit-condition? and exit? [ + stop + ][ + go-core fast-sharing? + ] +end + + + + + ; one go = one round -to go-core +to go-core [fast-sharing?] ask turtles [ pull ] - let fast-sharing (g-fast-sharing-enabled and converged-light) - if fast-sharing [ + if fast-sharing? [ share-fast ] ask turtles [ - if not fast-sharing [ + if not fast-sharing? [ share ] calc-posterior @@ -103,25 +124,6 @@ end -; advances the model one round with- or without evaluating the exit-condition -; depending on the argument: -; exit? = exit-condition evaluated?, type: boolean -to go [exit?] - with-local-randomness [ - if exit? and not g-exit-condition? [ - set g-exit-condition? exit-condition - ] - ] - ifelse g-exit-condition? and exit? [ - stop - ][ - go-core - ] -end - - - - ; some basic sanity checks, which ensure that the chosen model parameters are ; sensible