-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgroupFormationV02.nlogo
1418 lines (1267 loc) · 28.1 KB
/
groupFormationV02.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
;; EXPERIMENTAL BRANCH!!!! EXPERIMENTAL FEATURES!!!!!!!!
;;
;; This version of our joint model goes further and study the differences in opinion distributions
;; We form two camps -- C1 and C2 -- they could have their mean opinion <-1, +1> and their sigma <0, 1>,
;; but we could also mirror them: C1-average = - C2-average; C1-sigma = C2-sigma,
;; we could also determine size of C1 <0, 1>, whize size of C2 = 1 - C1-size.
;; Here the average opinion holds for all opinions defining opinion position, in principle we might flip averages from opinion to opinion, but situation is still same -- one camp has different opinion from the another camp.
;; the homophily/heterophily is applied as follows:
;; Homophily: we take the first 'N-agents' * 'C1-size' agents and for them we apply 'C1-average' and 'C1-sigma' when randomly drawing opinions,
;; the result is that whole segment of small-world has opinions drawn according the same principle and parameters.
;; Heterophily: every agent has 'C1-size' chance to use 'C1-average' and 'C1-sigma' for random drawing of opinions,
;; and 1 - 'C1-size' chance to use 'C2-average' and 'C2-sigma', the resul is well mixed public sphere.
;;
;; We apply mainly HK model, but Deffuant is still implemented in code and we look also at it in more than 1D and look how agents adapt in >1D opinion space and whether they form groups.
;;
;; Created: 2021-10-21 FranCesko
;; Edited: 2021-10-28 FranCesko
;; Encoding: windows-1250
;; NetLogo: 6.1.1
;;
;; IDEA: What about simply employ Spiral of Silence?
;; Just simply -- general parameter on scale (0; 1> and probability of speaking her attitude/opinion,
;; baseline is p==1, everybody speaks always, if p==0.5 so everybody has 0.5 probability to speak her opinion/attitude at given step,
;; if succeeds - speaks in given step, if not - falls silent for the respective step.
;; In HK mechanism, agent computes mean opinion of all speaking agents who are inside 'opinion boundary' (are not further than threshold).
;; In Defuant, agent randomly takes one speaking agent inside the 'opinion boundary' and sets opinon as average of their opinions.
;; DONE!
;;
;; IDEA: Employ homophily/heterophily principle at model start.
;; In progress ...
;;
;; IDEA: Choose, how many opinions agents update: sometimes 1, 2, 3, 4 ...
;; DONE!
;;
;; IDEA: Compute clusters
;; DONE!
;;
;; WISHLIST:
;; - differentiate between interpersonal communication and social media communication -- two overlapping networks with their own rules
;; - how radicalization is possible? How polarization happens?
;; - differential attraction
;; - repulsion
;; - media exposure will be crucial…we can ask abt opinion consistent content, opinion contrary, and “mainstream/mixed”…
;; how to we conceptualize/model those in ABM? Is this too simplistic (eg, think of the different flavors of conservative media,
;; ranging from CDU type media to extremist hate groups).
;; - how to think about social media influencers (eg Trump before deplatforming)…
;; is it possible to designate “superagents” who influence everyone sharing certain beliefs and see their effects…
;; both reach everyone in a group and their opinions are very highly weighted (or people vary in how much they weight that opinion?
;; Could estimate Twitter effect that way! Perhaps one could even model how movement towards an opinion might influence the superagent
;; to increase communication or change focus…
;; - Give weights to opinions... Taken from media, or from interpersonal communication:
;; -- agents pick opinion according the importance, and update importance according number of contacts regarding the opinion
;;
;;
;; Parameters:
;; Small-world network (Watts-Strogatz)
;; agents have more than 1 type of attitude
;; opinion on scale <-1;+1>
;; boundary -- defines range as fraction of maximum possible Eucleid distance in n-dimensional space, this maximum depends on number of opinions: sqrt(opinions * 4)
;;
;; TO-DO:
;; 1) stopping conditions -- DONE!
;;
extensions [nw]
turtles-own [Opinion-position Speak? Uncertainty Record Last-opinion]
globals [main-Record components positions]
;; Initialization and setup
to setup
ca
ask patches [set pcolor patch-color]
if set-seed? [random-seed RS]
nw:generate-watts-strogatz turtles links N-agents n-neis p-random [
fd (max-pxcor - 1)
set size (max-pxcor / 10)
set Opinion-position get-opinion
set Last-opinion Opinion-position
set Record n-values record-length [0]
set speak? speaking
set Uncertainty get-uncertainty
getColor
]
ask patches [set pcolor patch-color]
ask links [set hidden? TRUE]
ask turtles [getPlace]
set main-Record n-values record-length [0]
reset-ticks
end
to-report get-opinion
;; original algorithm: n-values opinions [precision (1 - random-float 2) 3]
let opinion n-values opinions [0] ;; empty list -- we will use separate streams so we need define empty variable independently before
ifelse homophily? [ ;; The first part is homophilic algorithm
let breaking-point (C1-size * N-agents)
let i 0
while [i < opinions] [
let o -2
while [o < -1 or o > 1] [
set o random-normal ifelse-value (who < breaking-point)[C1-average][C2-average] ifelse-value (who < breaking-point)[C1-sigma][C2-sigma]
]
set opinion replace-item i opinion o
set i (i + 1)
]
][ ;; The second part is heterophilic algorithm
let C1? (C1-size > random-float 1) ;; randomly ressolve whether agent is in C1 or C2
let i 0
while [i < opinions] [
let o -2
while [o < -1 or o > 1] [
set o random-normal ifelse-value (C1?)[C1-average][ifelse-value (mirror-C1?) [0 - C1-average][C2-average]] ifelse-value (C1?)[C1-sigma][ifelse-value (mirror-C1?) [C1-sigma][C2-sigma]]
]
set opinion replace-item i opinion o
set i (i + 1)
]
]
report opinion
end
to-report get-uncertainty
let uValue 0
if boundary-drawn = "constant" [set uValue boundary]
if boundary-drawn = "uniform" [set uValue precision (random-float (2 * boundary)) 3]
if boundary-drawn = "normal" [
set uValue precision (random-normal boundary sigma) 3
while [uValue < 0 or uValue > 1] [
set uValue precision (random-normal boundary sigma) 3
]
]
report uValue
end
to getPlace
if X-opinion > opinions [set X-opinion 1]
if Y-opinion > opinions [set Y-opinion 1]
facexy ((item (X-opinion - 1) opinion-position) * max-pxcor) ((item (Y-opinion - 1) opinion-position) * max-pycor)
set xcor (item (X-opinion - 1) opinion-position) * max-pxcor
set ycor (item (Y-opinion - 1) opinion-position) * max-pycor
end
to getColor
ifelse speak? [
set color 15 + 4 * mean(opinion-position)
set size (max-pxcor / 10)
][
set color white
set size 0
]
end
to-report speaking
report p-speaking > random-float 1
end
to-report patch-color
report 59.9 - (4.9 * (ln(1 + count turtles-here) / ln(N-agents)))
end
;; Main routine
to go
if updating > opinions [set updating opinions]
ask turtles [
;; speaking
set speak? speaking
set Last-opinion Opinion-position
;; Mechanism of opinion change
ifelse model = "HK" [
change-opinion-HK
][
change-opinion-Deffuant
]
;; Getting place and coloring
getColor
getPlace
]
ask patches [set pcolor patch-color]
ask turtles [
;; we take 1 if opinion is same, we take 0 if opinion changes, then
;; we put on the start of the list Record, but we omit the last item from Record
set Record fput ifelse-value (Last-opinion = Opinion-position) [1][0] but-last Record
]
set main-Record fput precision (mean [mean Record] of turtles) 3 but-last main-Record
tick
if mean main-Record = 1 [last-steps stop]
end
to last-steps
set components []
set positions []
while [count turtles > 0] [
ask one-of turtles [
let comp turtles with [opinion-position = [opinion-position] of myself]
if count comp > smallest-component [
set components fput count comp components
set positions fput ([opinion-position] of one-of comp) positions
]
ask comp [die]
]
]
print components
print positions
end
to change-opinion-HK
let X-guys link-neighbors with [color != white]
let lim-dist (Uncertainty * sqrt(opinions * 4))
let influentials X-guys with [opinion-distance <= lim-dist]
;print lim-dist
;print sort [opinion-distance] of influentials
if count influentials > 0 [
let op-list shuffle (n-of updating (range opinions)) ;; here we draw a list of dimensions which we will update
let steps updating
let step 0
while [step < steps] [
let i item step op-list
let their-op precision (mean [item i opinion-position] of influentials) 3
set opinion-position replace-item i opinion-position their-op ;; NOTE: H-K model really assumes that agent adopts immediatelly the 'consesual' position
set step step + 1
]
;print step
]
; print opinion-position
; print [opinion-position] of influentials
; print [opinion-distance] of influentials
; print mean [item (X-opinion - 1) opinion-position] of influentials
end
to change-opinion-Deffuant
let influentials link-neighbors with [color != white]
set influentials influentials with [opinion-distance <= (Uncertainty * sqrt(opinions * 4))]
if count influentials > 0 [
let op-list shuffle n-of updating range opinions ;; here we draw a list of dimensions which we will update
let partner one-of influentials
let steps updating
let step 0
while [step < steps] [
let myX item (item step op-list) opinion-position
let herX item (item step op-list) [opinion-position] of partner
let myU Uncertainty
let herU [Uncertainty] of partner
let Hij (min list (myX + myU) (herX + herU)) - (max list (myX - myU) (herX - herU))
if Hij > herU [
set opinion-position replace-item (item step op-list) opinion-position precision (myX + (mu * ((Hij / herU) - 1) * (herX - myX))) 3
set Uncertainty precision (myU + (mu * ((Hij / herU) - 1) * (herU - myU))) 3
]
set step step + 1
]
]
end
to-report opinion-distance
let my opinion-position
let her [opinion-position] of myself
let steps length my
let step 0
let dist 0
while [step < steps] [
set dist dist + (item step my - item step her) ^ 2
set step step + 1
]
set dist sqrt dist
;print dist
report dist
end
@#$#@#$#@
GRAPHICS-WINDOW
219
10
667
459
-1
-1
40.0
1
10
1
1
1
0
0
0
1
-5
5
-5
5
1
1
1
ticks
30.0
BUTTON
109
10
164
43
NIL
setup
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
163
42
218
75
GO!
go
T
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
163
10
218
43
Step
go\n;ask turtles [\n; set speak? TRUE\n; getColor\n;]
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
SLIDER
22
246
194
279
N-agents
N-agents
10
1000
400.0
10
1
NIL
HORIZONTAL
SLIDER
877
10
1049
43
n-neis
n-neis
1
150
50.0
1
1
NIL
HORIZONTAL
SLIDER
877
46
1049
79
p-random
p-random
0
0.5
0.02
0.01
1
NIL
HORIZONTAL
SLIDER
23
280
195
313
opinions
opinions
1
50
4.0
1
1
NIL
HORIZONTAL
BUTTON
27
469
82
502
getPlace
ask turtles [getPlace]
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
CHOOSER
4
10
96
55
model
model
"HK" "Deffuant"
0
SLIDER
23
312
195
345
p-speaking
p-speaking
0
1
1.0
0.01
1
NIL
HORIZONTAL
SLIDER
24
345
196
378
boundary
boundary
0.01
1
0.15
0.01
1
NIL
HORIZONTAL
INPUTBOX
676
10
748
70
RS
5.0
1
0
Number
SWITCH
749
10
859
43
set-seed?
set-seed?
0
1
-1000
BUTTON
84
469
139
502
getColor
ask turtles [\n set speak? TRUE\n getColor\n]
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
140
471
195
504
inspect
inspect turtle 0\nask turtle 0 [print opinion-position]
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
195
471
250
504
sizes
show sort remove-duplicates [count turtles-here] of turtles
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
250
471
305
505
HIDE!
\nask turtles [set hidden? TRUE]
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
303
473
358
506
SHOW!
\nask turtles [set hidden? FALSE]\nask turtles [set size (max-pxcor / 10)]
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
CHOOSER
4
88
96
133
boundary-drawn
boundary-drawn
"uniform" "constant"
0
SLIDER
24
410
196
443
sigma
sigma
0
1
0.05
0.01
1
NIL
HORIZONTAL
PLOT
1284
262
1484
382
Distribution of 'Uncertainty'
NIL
NIL
0.0
1.0
0.0
10.0
true
false
"" ""
PENS
"default" 0.05 1 -16777216 true "" "histogram [Uncertainty] of turtles"
SLIDER
24
377
196
410
mu
mu
0.01
1
1.0
0.01
1
NIL
HORIZONTAL
BUTTON
358
473
449
506
avg. Uncertainty
show mean [Uncertainty] of turtles
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
445
473
507
506
Hide links
ask links [set hidden? TRUE]
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
BUTTON
507
473
567
506
Show links
ask links [set hidden? FALSE]
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
SLIDER
1055
10
1227
43
X-opinion
X-opinion
1
50
1.0
1
1
NIL
HORIZONTAL
SLIDER
1056
47
1228
80
Y-opinion
Y-opinion
1
50
2.0
1
1
NIL
HORIZONTAL
BUTTON
566
473
637
506
avg. Opinion
show mean [mean opinion-position] of turtles
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
PLOT
674
258
1277
495
Developement of opinions
NIL
NIL
0.0
10.0
-0.01
0.01
true
true
"" ""
PENS
"Op01" 1.0 0 -16777216 true "" "plot mean [item 0 opinion-position] of turtles"
"Op02" 1.0 0 -7500403 true "" "if opinions >= 2 [plot mean [item 1 opinion-position] of turtles]"
"Op03" 1.0 0 -2674135 true "" "if opinions >= 3 [plot mean [item 2 opinion-position] of turtles]"
"Op04" 1.0 0 -955883 true "" "if opinions >= 4 [plot mean [item 3 opinion-position] of turtles]"
"Op05" 1.0 0 -6459832 true "" "if opinions >= 5 [plot mean [item 4 opinion-position] of turtles]"
"Op06" 1.0 0 -1184463 true "" "if opinions >= 6 [plot mean [item 5 opinion-position] of turtles]"
"Op07" 1.0 0 -10899396 true "" "if opinions >= 7 [plot mean [item 6 opinion-position] of turtles]"
"Op08" 1.0 0 -13840069 true "" "if opinions >= 8 [plot mean [item 7 opinion-position] of turtles]"
"Op09" 1.0 0 -14835848 true "" "if opinions >= 9 [plot mean [item 8 opinion-position] of turtles]"
"Op10" 1.0 0 -11221820 true "" "if opinions >= 10 [plot mean [item 9 opinion-position] of turtles]"
"Op11" 1.0 0 -13791810 true "" "if opinions >= 11 [plot mean [item 10 opinion-position] of turtles]"
SLIDER
4
55
96
88
updating
updating
1
50
2.0
1
1
NIL
HORIZONTAL
PLOT
674
107
1311
257
Stability of turtles (average)
NIL
NIL
0.0
10.0
0.0
1.0
true
true
"" ""
PENS
"Turtles" 1.0 0 -16777216 true "" "plot mean [mean Record] of turtles"
"Main record" 1.0 0 -2674135 true "" "plot mean main-Record"
BUTTON
675
73
752
106
avg. Record
show mean [mean Record] of turtles
NIL
1
T
OBSERVER
NIL
NIL
NIL
NIL
1
MONITOR
764
47
868
92
avg. Record
mean [mean Record] of turtles
6
1
11
SLIDER
1251
46
1423
79
record-length
record-length
10
100
100.0
1
1
NIL
HORIZONTAL
SLIDER
1252
13
1424
46
smallest-component
smallest-component
1
10
2.0
1
1
NIL
HORIZONTAL
SWITCH
96
75
218
108
homophily?
homophily?
1
1
-1000
SLIDER
96
140
218
173
C1-average
C1-average
-1
1
0.4
0.01
1
NIL
HORIZONTAL
SLIDER
96
173
218
206
C2-average
C2-average
-1
1
-0.3
0.01
1
NIL
HORIZONTAL
SLIDER
96
108
218
141
C1-size
C1-size
0
1
0.5
0.01
1
NIL
HORIZONTAL
SLIDER
1
140
96
173
C1-sigma
C1-sigma
0
1
0.2
0.01
1
NIL
HORIZONTAL
SLIDER
1
173
96
206
C2-sigma
C2-sigma
0
1
0.15
0.01
1
NIL
HORIZONTAL
SWITCH
1338
86
1434
119
mirror-C1?
mirror-C1?
1
1
-1000
@#$#@#$#@
## WHAT IS IT?
(a general understanding of what the model is trying to show or explain)
## HOW IT WORKS
(what rules the agents use to create the overall behavior of the model)
## HOW TO USE IT
(how to use the model, including a description of each of the items in the Interface tab)
## THINGS TO NOTICE
(suggested things for the user to notice while running the model)
## THINGS TO TRY