From 6212fbe9178be9985fb291737b77e29556efb09c Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Thu, 21 Jun 2018 14:55:08 +0200 Subject: [PATCH 1/4] 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/4] `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 From be1c77e1851713f9e57e5ddf3d1ce3271aeacd16 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Thu, 25 Oct 2018 20:08:46 +0200 Subject: [PATCH 3/4] Tracking construct for research time added * Currently we don't know how much time researchers spend on each theory apart from when they are all converged on one theory * In ArgABM we use research time as basis for one of our diversity measures. To allow the same measurement in SocNet we introduce two new globals: `g-research-time` and `g-myscientists` and a new procedure `compute-popularity` which records how much scientists are on each theory during the run * The popularity plot in the interface utilizes the new global `g-myscientists` instead of computing the distribution itself every time. This reduces computational load (marginally) --- SocNetABM.nlogo | 12 +++++++++--- protocol.nls | 11 +++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/SocNetABM.nlogo b/SocNetABM.nlogo index bc7d826..c1e4395 100644 --- a/SocNetABM.nlogo +++ b/SocNetABM.nlogo @@ -7,7 +7,8 @@ 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-exit-condition?] + g-conv-start-th1 g-conv-start-th2 g-exit-condition? g-myscientists + g-research-time] __includes ["protocol.nls"] @@ -53,6 +54,7 @@ to setup [rs] let th-1-scientist count turtles with [mytheory = 0] let th-2-scientist count turtles with [mytheory = 1] set run-start-scientists-save (list th-1-scientist th-2-scientist) + set g-myscientists run-start-scientists-save set g-depressed-confidence false set g-last-convlight-th -1 set g-conv-dur-th1 [] @@ -60,6 +62,7 @@ to setup [rs] set g-conv-start-th1 [] set g-conv-start-th2 [] set g-exit-condition? false + set g-research-time [0 0] reset-ticks end @@ -118,6 +121,9 @@ to go-core [fast-sharing?] and not member? mytheory cur-best-th] [ act-on-strategies ] + with-local-randomness [ + compute-popularity + ] tick end @@ -619,8 +625,8 @@ true false "" "" PENS -"best theory" 1.0 0 -2674135 true "" "plot count turtles with [mytheory = 0]" -"not-best-theory" 1.0 0 -14835848 true "" "plot count turtles with [mytheory = 1]" +"best theory" 1.0 0 -2674135 true "" "plot item 0 g-myscientists" +"not-best-theory" 1.0 0 -14835848 true "" "plot item 1 g-myscientists" SWITCH 16 diff --git a/protocol.nls b/protocol.nls index b8ab0d9..653b51b 100644 --- a/protocol.nls +++ b/protocol.nls @@ -529,3 +529,14 @@ to-report center-of-convergence [th#] 2 * curstart * curlength + curlength ^ 2] convergence-starts conv-durations) report weighted-convergences / (2 * cur-cum-conv-dur) end + + + + + +to compute-popularity + set g-research-time (map + g-research-time g-myscientists) + let th-1-scientist count turtles with [mytheory = 0] + let th-2-scientist scientists - th-1-scientist + set g-myscientists (list th-1-scientist th-2-scientist) +end From 645b6dbd8c4020e7f67ec43bde27233836c8b841 Mon Sep 17 00:00:00 2001 From: Daniel Frey Date: Fri, 26 Oct 2018 03:43:26 +0200 Subject: [PATCH 4/4] Reporter for research-time added * Our runs are supposed to end at the time when scientists finally converge, even though they might practically last longer. A snapshot of the research-time the scientists spent investigating each theory must therefore be stored at the point when researchers converge. * This snapshot of research-time is stored via the convergence-reporters together with- and in the same way as- other variables which are recorded at the point of convergence * The default BehaviorSpace experiment then uses this reporter to record the research time for each theory * Documentation for the two new globals has been added --- README.md | 14 ++++++++++++++ SocNetABM.nlogo | 19 ++++++++++++++++++- protocol.nls | 21 +++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 209cc6f..8d761d0 100644 --- a/README.md +++ b/README.md @@ -139,6 +139,20 @@ When the network is a de facto complete network, scientists might be able to uti 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. +#### g-myscientists + +* format: list +* example: [3 7] + +Reflects how many scientist are currently researching each theory: the first entry in the list is for theory one the 2nd entry for theory two. + +#### g-research-time + +* format: list +* example: [350 129] + +Records how much each theory has been researched over the course of the run: each round each researcher who pulls from the slot machine for a given theory increases the counter for this theory by one. The first entry in the list is for theory one the 2nd entry for theory two. + ### Turtles-own diff --git a/SocNetABM.nlogo b/SocNetABM.nlogo index c1e4395..b2f776c 100644 --- a/SocNetABM.nlogo +++ b/SocNetABM.nlogo @@ -162,7 +162,7 @@ end to init-converge-reporters set converge-reporters (list [ -> average-belief 0 true] [ -> average-cum-successes 0 true] [ -> average-confidence true] - [ -> average-signal 0 true]) + [ -> average-signal 0 true] [ -> research-time 0 true]) end @@ -891,6 +891,21 @@ When the network is a de facto complete network, scientists might be able to uti 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. +#### g-myscientists + +* format: list +* example: [3 7] + +Reflects how many scientist are currently researching each theory: the first entry in the list is for theory one the 2nd entry for theory two. + +#### g-research-time + +* format: list +* example: [350 129] + +Records how much each theory has been researched over the course of the run: each round each researcher who pulls from the slot machine for a given theory increases the counter for this theory by one. The first entry in the list is for theory one the 2nd entry for theory two. + + ### Turtles-own #### cur-best-th @@ -1335,6 +1350,8 @@ NetLogo 6.0.4 frequency-converged "th2" center-of-convergence "th1" center-of-convergence "th2" + research-time "th1" false + research-time "th2" false diff --git a/protocol.nls b/protocol.nls index 653b51b..16c98cd 100644 --- a/protocol.nls +++ b/protocol.nls @@ -540,3 +540,24 @@ to compute-popularity let th-2-scientist scientists - th-1-scientist set g-myscientists (list th-1-scientist th-2-scientist) end + + + + + +; reports the time scientists spent researching each theory before they finally +; converged +; arguments: +; - th# = theory, type: string +; - rec? = recording?, type: boolean +to-report research-time [th# rec?] + let identifier "restime" + ifelse rec? [ + report (fput identifier g-research-time) + ][ + set th# translate-from-string th# + let res-time but-first first filter [curitem -> + first curitem = identifier] converge-reporters-values + report item th# res-time + ] +end