-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathSocNetABM.nlogo
1383 lines (1120 loc) · 31.9 KB
/
SocNetABM.nlogo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
turtles-own [a b theory-jump times-jumped cur-best-th current-theory-info
mytheory successes subj-th-i-signal crit-interact-lock confidence
avg-neighbor-signal share-group]
globals [th-i-signal indiff-count crit-interactions-th1 crit-interactions-th2
confidence-cutoff converged-ticks last-converged-th
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]
__includes ["protocol.nls"]
; initializes the world
to setup [rs]
clear-all
set rndseed rs
random-seed rs
check-sanity
init-hidden-variables
init-converge-reporters
set th-i-signal list th1-signal th2-signal
set-default-shape turtles "person"
create-turtles scientists [
; a1(2) is the prior alpha for theory 1(2) for a given scientist. The same
; applies to b1(2) which stands for prior beta of theory 1(2).
let a1 init-ab
let b1 init-ab
let a2 init-ab
let b2 init-ab
set a list a1 a2
; b contains the denominator of the mean of the beta distribution (i.e.
; alpha + beta): the first (second) entry is the denominator for
; theory 1 (2).
set b (list (a1 + b1) (a2 + b2))
; calculate the prior (i.e. mean of the beta distribution) from the random
; alphas / betas.
calc-posterior
compute-strategies
set mytheory one-of cur-best-th
set-researcher-colors
set subj-th-i-signal th-i-signal
]
create-network
ask turtles [
set share-group (turtle-set link-neighbors self)
]
set g-fast-sharing-enabled (network-structure = "complete"
or (network-structure = "wheel" and scientists <= 4)
or (network-structure = "cycle" and scientists <= 3) )
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-depressed-confidence false
set g-last-convlight-th -1
set g-conv-dur-th1 []
set g-conv-dur-th2 []
set g-conv-start-th1 []
set g-conv-start-th2 []
reset-ticks
end
; one go = one round
to go
ask turtles [
pull
]
let fast-sharing (g-fast-sharing-enabled and converged-light)
if fast-sharing [
share-fast
]
ask turtles [
if not fast-sharing [
share
]
calc-posterior
compute-strategies
if crit-interact-lock > 0 [
set crit-interact-lock crit-interact-lock - 1
]
]
if nature-evidence-frequency > 0 and ticks != 0
and ticks mod nature-evidence-frequency = 0 [
ask turtles [
update-from-nature
]
set g-depressed-confidence false
]
ask turtles with [crit-interact-lock = 0
and not member? mytheory cur-best-th] [
act-on-strategies
]
tick
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]
]
end
; some basic sanity checks, which ensure that the chosen model parameters are
; sensible
to check-sanity
ifelse critical-interaction or nature-evidence-frequency > 0 [
if th1-aps < th2-aps [
error "th1-aps must be higher than th2-aps (th1 is the better theory)"
]
][
if th1-signal < th2-signal [
error "th1-signal must be higher than th2-signal (th1 is the better theory)"
]
]
end
; initializes the hidden variables (= not set in the interface)
to init-hidden-variables
set confidence-cutoff 1 - (1 / 10 ^ 4)
end
; the reporters which have to be collected when researchers converge.
to init-converge-reporters
set converge-reporters (list [ -> average-belief 0 true]
[ -> average-cum-successes 0 true] [ -> average-confidence true]
[ -> average-signal 0 true])
end
; generates the alphas & betas for the researchers priors
to-report init-ab
if uninformative-priors [
report max-prior / 2
]
; this formulation prevents drawing values of zero. It reports
; a random-float from the interval (0 , max-prior]
report (max-prior - random-float max-prior)
end
; arranging the researchers in the respective social-networks
to create-network
if network-structure = "cycle" [
let turtle-list sort turtles
create-network-cycle turtle-list
]
if network-structure = "complete" [
create-network-complete
]
if network-structure = "wheel" [
create-network-wheel
]
end
; arranging the researchers in a complete-graph
to create-network-complete
ask turtles [ create-links-with other turtles ]
layout-circle turtles (world-width / 2 - 1)
end
; arranging the researchers in a cycle
to create-network-cycle [turtle-list]
let previous-turtle 0
foreach turtle-list [ [cur-turtle] ->
ask cur-turtle [
ifelse previous-turtle != 0 [
create-link-with previous-turtle
set previous-turtle self
][
create-link-with last turtle-list
set previous-turtle self
]
]
]
layout-circle turtle-list (world-width / 2 - 1)
end
; arranging the researchers in a wheel
to create-network-wheel
; first the cycle is created...
let turtle-list sort turtles
create-network-cycle but-first turtle-list
; and then the royal family connects to all other scientists
ask first turtle-list [
setxy 0 0
create-links-with other turtles
]
end
; reports a draw from the binomial distribution with n pulls and probability p
to-report binomial [n p]
report length filter [ ?1 -> ?1 < p ] n-values n [random-float 1]
end
; Researchers pull from their respective slot machine:
; the binomial distribution is approximated by the normal distribution with
; the same mean and variance. This approximation is highly accurate for all
; parameter values from the interface.
; B/c the normal distribution is a continuous distribution the outcome is
; rounded and there is a safety check which constrains the distribution to the
; interval [0, pulls] to prevent negative- or higher than pulls numbers of
; successes
to pull
let mysignal item mytheory subj-th-i-signal
set successes [0 0]
ifelse pulls > 100 [
let successes-normal round random-normal
(pulls * mysignal) sqrt (pulls * mysignal * (1 - mysignal) )
ifelse successes-normal > 0 and successes-normal <= pulls [
set successes replace-item mytheory successes successes-normal
][
if successes-normal > pulls [
set successes replace-item mytheory successes pulls
]
]
][
let successes-binomial binomial pulls mysignal
set successes replace-item mytheory successes successes-binomial
]
end
; the sharing of information between researchers in case that they are all on
; the same theory and the structure of the network is equivalent to "complete".
to share-fast
let cur-theory [mytheory] of one-of turtles
let cum-successes sum [item cur-theory successes] of turtles
let cum-pulls pulls * scientists
ask turtles [
set a replace-item cur-theory a (item cur-theory a + cum-successes)
set b replace-item cur-theory b (item cur-theory b + cum-pulls)
]
end
; the sharing of information between researchers optionally including
; critical-interaction
to share
let cur-turtle self
let cur-turtle-th mytheory
; first list entry is th1 2nd is th2
let successvec [0 0]
let pullcounter [0 0]
ask share-group [
ifelse mytheory = cur-turtle-th or not critical-interaction [
set successvec (map + successvec successes)
set pullcounter replace-item mytheory pullcounter
(item mytheory pullcounter + pulls)
][
let other-successes successes
let other-theory mytheory
let other-success-ratio ((item mytheory successes) / pulls)
if other-success-ratio > item mytheory [current-theory-info] of
cur-turtle [
ask cur-turtle [
evaluate-critically
]
]
ask cur-turtle [
set a (map + a other-successes)
set b replace-item other-theory b (item other-theory b + pulls)
calc-posterior
]
]
]
set a (map + a successvec)
set b (map + b pullcounter)
end
; If researchers communicate with researchers from another theory they might
; interact critically
to evaluate-critically
let actual-prob-suc 0
ifelse mytheory = 0 [
set crit-interactions-th1 crit-interactions-th1 + 1
set actual-prob-suc th1-aps
][
set crit-interactions-th2 crit-interactions-th2 + 1
set actual-prob-suc th2-aps
]
if crit-interact-lock = 0 [
set crit-interact-lock crit-jump-threshold + 1
]
let old-th-i-signal item mytheory subj-th-i-signal
set subj-th-i-signal replace-item mytheory subj-th-i-signal (old-th-i-signal
+ (actual-prob-suc - old-th-i-signal) * crit-strength)
end
; calculates from a given a (= alpha) and b (= alpha + beta) the belief of a
; researcher i.e. the mean of the beta distribution
to calc-posterior
set current-theory-info (map / a b)
end
; Researchers determine which theories they currently consider best theories
to compute-strategies
let max-score max current-theory-info
let best-th-position position max-score current-theory-info
; if the other entry is in the interval for best theories it is also added
let other-score item ((best-th-position + 1) mod 2) current-theory-info
ifelse other-score >= max-score - strategy-threshold [
set cur-best-th [0 1]
set indiff-count indiff-count + 1
][
set cur-best-th (list best-th-position)
]
end
to update-from-nature
let actual-prob-suc 0
ifelse mytheory = 0 [
set actual-prob-suc th1-aps
][
set actual-prob-suc th2-aps
]
let old-th-i-signal item mytheory subj-th-i-signal
set subj-th-i-signal replace-item mytheory subj-th-i-signal (old-th-i-signal
+ (actual-prob-suc - old-th-i-signal) * crit-strength)
end
; Researchers potentially switch to the other theory
to act-on-strategies
set theory-jump theory-jump + 1
if theory-jump = jump-threshold + 1 [
; set mytheory to the other theory
set mytheory ((mytheory + 1) mod 2)
set-researcher-colors
set times-jumped times-jumped + 1
set theory-jump 0
]
end
; The researchers' color depends on the theory she's working on
to set-researcher-colors
ifelse mytheory = 0 [
set color red
][
set color turquoise
]
end
@#$#@#$#@
GRAPHICS-WINDOW
234
10
671
448
-1
-1
13.0
1
10
1
1
1
0
0
0
1
-16
16
-16
16
1
1
1
ticks
30.0
SLIDER
235
466
407
499
th1-signal
th1-signal
0.1
0.9
0.5
0.001
1
NIL
HORIZONTAL
SLIDER
236
512
408
545
th2-signal
th2-signal
0.1
0.9
0.499
0.001
1
NIL
HORIZONTAL
SLIDER
14
255
186
288
pulls
pulls
1
6000
1000.0
1
1
NIL
HORIZONTAL
SLIDER
15
307
187
340
max-prior
max-prior
1
10000
4.0
1
1
NIL
HORIZONTAL
SLIDER
238
552
410
585
jump-threshold
jump-threshold
0
1000
0.0
1
1
NIL
HORIZONTAL
SLIDER
15
116
187
149
scientists
scientists
3
100
10.0
1
1
NIL
HORIZONTAL
SLIDER
428
554
600
587
strategy-threshold
strategy-threshold
0
1
0.0
0.001
1
NIL
HORIZONTAL
BUTTON
21
14
84
47
setup
setup new-seed
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
101
15
164
48
NIL
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
0
CHOOSER
16
400
154
445
network-structure
network-structure
"cycle" "wheel" "complete"
0
PLOT
692
21
892
171
Popularity
Time steps
scientists
0.0
100.0
0.0
10.0
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]"
SWITCH
16
456
170
489
critical-interaction
critical-interaction
1
1
-1000
SLIDER
16
504
188
537
crit-strength
crit-strength
1 / 10000
1 / 10
0.001
1 / 10000
1
NIL
HORIZONTAL
SLIDER
17
548
201
581
crit-jump-threshold
crit-jump-threshold
0
1000
0.0
1
1
NIL
HORIZONTAL
BUTTON
50
64
124
97
NIL
go-stop
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
0
SLIDER
15
162
187
195
max-ticks
max-ticks
0
100000
100000.0
100
1
NIL
HORIZONTAL
SLIDER
15
206
217
239
nature-evidence-frequency
nature-evidence-frequency
0
1000
0.0
1
1
NIL
HORIZONTAL
SLIDER
426
468
598
501
th1-aps
th1-aps
0
1
0.5
0.001
1
NIL
HORIZONTAL
SLIDER
426
512
598
545
th2-aps
th2-aps
0
1
0.499
0.001
1
NIL
HORIZONTAL
SWITCH
16
357
183
390
uninformative-priors
uninformative-priors
1
1
-1000
@#$#@#$#@
# UNDER CONSTRUCTION
# SocNetABM
NetLogo iteration of Zollman's (2010) ABM with critical interaction.
## HOW IT WORKS
Beliefs of the researchers are modeled via a beta distribution: The mean of the beta distribution is their current belief.
## NETLOGO FEATURES
The binomial distribution is approximated by the normal distribution with the same mean and variance. This approximation is highly accurate for all parameter values from the interface.
B/c the normal distribution is a continuous distribution the outcome is rounded and there is a safety check which constrains the distribution to the interval [0, pulls] to prevent negative- or higher than pulls numbers of successes.
## Variables
Default-values have been set to mirror Zollman's (2010) model. The slider ranges are mostly set to mirror the ranges considered by Rosenstock et al. (2016) ( pulls correspond to `n` in Rosenstock et al.(2016)). The exceptions are:
* The signal ranges have a larger interval
### Globals
#### th-i-signal
* type: float-list
* example: [0.5 0.499]
The average objective probability of success (ops)for [theory-1 theory-2].
#### indiff-count
* type: integer
* example: 1003
The sum of number of rounds each scientist was indifferent between the two theories.
#### crit-interactions-th1(2)
* type: integer
* example: 56
The sum of critical interactions scientists on theory 1(2) encountered.
#### confidence-cutoff
* type: integer
* example: 0.9999
The global-confidence `g-confidence` must be higher than this value for the run to be terminated.
#### converged-ticks
* type: integer
* example: 114
The number of ticks which have passed since the researchers converged for the last time.
#### last-converged-th
* type: integer
* example: 0
The theory the researchers converged on the last time they converged: 0 = th1, 1 = th2
#### max-ticks
* type: integer
* example: 10000
The maximal number of rounds before a run is terminated by the exit condition.
#### converge-reporters
* type: anonymous reporters list
* example: [(anonymous reporter: [ average-belief 0 true ]) (anonymous reporter: [ average-cum-successes 0 true ]) (anonymous reporter: [ average-confidence true ]) (anonymous reporter: [ average-signal 0 true ])]
Reporters which have to be collected in the round when researchers converge. The values for those reporters is then stored in the global `converge-reporters-values` and retrieved by BehaviourSpace at the end of the run.
#### converge-reporters-values
* type: list
* example: [["avgbelief" 0.4997690253321044 0.49127250748536755] ["avgsuc" 110667.02991226684 21169.651936606337] ["avgconfidence" 0.7645093577413972] ["avgsignal" 0.5 0.499]]
The values from the anonymous reporters in `converge-reporters`, recorded at the last time researchers converged.
#### run-start-scientists-save
* type: integer-list
* example: [5 5]
The number of scientists on [th1 th2] at the beginning of the run.
#### rndseed
* format: integer
* example: -2147452934
Stores the random-seed of the current run.
#### g-confidence
* format: float
* example: 0.9993
Global-confidence: the probability that not a single researcher will switch theories i.e. the probability that this convergence is final. Range: [0,1]
#### g-depressed-confidence
* format: boolean
* example: false
If there is a researcher for whom, if given sufficient time for her belief to converge to the average signal of her and her link-neighbors, this would this be enough to abandon her current theory, her confidence will always be zero and therefore `g-confidence` will also be zero. In this case `g-depressed-confidence` will be set to true in order to avoid redundant confidence calculations.
#### g-fast-sharing-enabled
* format: boolean
* example: true
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.
### Turtles-own
#### cur-best-th
* type: integer-list
* example: [0 1] or [0]
The theories the researcher currently considers best: 0 = theory 1, 1 = theory 2. Can be a singleton.
#### current-theory-info
* type: float-list
* example: [0.44945 0.594994]
Contains the researchers current evaluation of the two theories. Entry 1 is the evaluation for the first theory and entry 2 for second.
#### mytheory
* type: integer
* example: 0
The theory the researcher is currently working on i.e. the theory she pulls from: 0 = theory 1, 1 = theory 2
#### successes
* type: integer-list
* example: [512 0] or [0 483]
The number of successes from her pulls this round: first entry successes for th1, 2nd: th2. One entry is always 0 b/c the researcher is pulling only from one theory at a time.
#### a
* type: float-list
* example [4501.309490 208.489044]
The alpha of the researchers memory in the beta distribution, i.e. the accumulated number of successes (including the prior). The first entry is the alpha for theory 1 the 2nd for theory 2.
#### b
* type: float-list
* example [9788.309490 500.489044]
Each entry: the alpha + beta of the researchers memory in the beta distribution, i.e. the accumulated number of pulls (including the prior). The first entry is the pulls for theory 1 the 2nd for theory 2.
#### theory-jump
* type: integer
* example: 0
How often the researcher considered jumping to another theory since the last jump.
#### times-jumped
* type: integer
* example: 42
How often the researcher switched theories.
#### subj-th-i-signal
* type: float-list
* example: [0.5 0.499]
The current objective probability of success (ops) the researcher has for [theory-1 theory-2].
#### crit-interact-lock
* type: integer
* example: 3
For how many more rounds the researcher is blocked from pursuing strategies (i.e. consider jumping / jump) b/c of critical interaction.
#### confidence
* type: float
* example 1337.94038
How confident the researcher is in the fact that her current best theory is actually the best theory (i.e. how unlikely it is that she will change her mind). Only calculated once all researchers have converged to one theory.
#### avg-neighbor-signal
* type: float
* example: 0.499
Only set once all researchers converged. This is the average signal the researcher and her link-neighbors currently observe for the theory they converged on.
#### share-group
* type: turtle-set
* example: (agentset, 3 turtles)
Contains all the scientists this scientist will share information with, including herself. This exists for performance reasons and will be set during `setup`.
## CREDITS AND REFERENCES
The numerical approximation for the error function is taken from:
Numerical Recipes in Fortran 77: The Art of Scientific Computing (ISBN 0-521-43064-X), 1992, page 214, Cambridge University Press.
via WIKIPEDIA. (2017) URL: https://en.wikipedia.org/wiki/Error_function#Numerical_approximations. Accessed: 2017-04-06.
Rosenstock, S., Bruner, J. P., & O'Connor, C. (2016). In Epistemic Networks, Is Less Really More?.
Zollman, K. J. (2010). The epistemic benefit of transient diversity. Erkenntnis, 72(1), 17.
@#$#@#$#@
default
true
0
Polygon -7500403 true true 150 5 40 250 150 205 260 250
airplane
true
0
Polygon -7500403 true true 150 0 135 15 120 60 120 105 15 165 15 195 120 180 135 240 105 270 120 285 150 270 180 285 210 270 165 240 180 180 285 195 285 165 180 105 180 60 165 15
arrow
true
0
Polygon -7500403 true true 150 0 0 150 105 150 105 293 195 293 195 150 300 150
box
false
0
Polygon -7500403 true true 150 285 285 225 285 75 150 135
Polygon -7500403 true true 150 135 15 75 150 15 285 75
Polygon -7500403 true true 15 75 15 225 150 285 150 135
Line -16777216 false 150 285 150 135
Line -16777216 false 150 135 15 75
Line -16777216 false 150 135 285 75