q-voter model (expressed & private opinions)
Model was written in NetLogo 6.3.0
•
Viewed 105 times
•
Downloaded 3 times
•
Run 0 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
Info tab cannot be displayed because of an encoding error
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
;; Copyright Barbara Kamińska 2024;; ;; implementation of Watts-Strogatz network taken from https://github.com/fsancho/Complex-Networks-Toolbox/blob/master/Complex%20Networks%20Model%206.nlogo globals [diss diss_1000 priv_p_1000 pub_p_1000 avg_priv avg_pub avg_diss target q-voters size_normal size_highlight] turtles-own [priv pub] to setup clear-all set size_normal 2 set size_highlight 3 ask patches [set pcolor white] create-turtles N [ set size size_normal ifelse (random 100) < density_of_ones [ set shape "pp" set priv 1 set pub 1 ] [ set shape "mm" set priv -1 set pub -1 ] ] layout-circle sort turtles 14 ;; initial wiring let neigh (n-values (k / 2) [ [i] -> i + 1 ]) ifelse k < N [ ask turtles [ let tar who foreach neigh [ [i] -> create-link-with (turtle ((tar + i) mod N)) ] ] ;; rewiring ask links [ let if_rewired false if (random-float 1) < beta[ let node1 end1 if [ count link-neighbors ] of node1 < (N - 1) [ let node2 one-of turtles with [ (self != node1) and (not link-neighbor? node1)] ask node1 [ create-link-with node2 [ set if_rewired true ] ] ] ] if (if_rewired)[ die ] ] ][ display user-message (word "Select k < N") ] ask turtles [ set label-color black ] set q-voters nobody set priv_p_1000 [] set pub_p_1000 [] set diss_1000 [] set avg_priv 0 set avg_pub 0 set avg_diss 0 reset-ticks end to setup-algorithm clear-all set size_normal 3 set size_highlight 5 ask patches [set pcolor white] create-turtles N [ set size size_normal ifelse (random 100) < density_of_ones [ set pub 1 ifelse (random-float 1) < 0.5 [set priv 1][set priv -1] ] [ set pub -1 ifelse (random-float 1) < 0.5 [set priv 1][set priv -1] ] ] layout-circle sort turtles 12 ;; initial wiring let neigh (n-values (k / 2) [ [i] -> i + 1 ]) ifelse k < N [ ask turtles [ let tar who foreach neigh [ [i] -> create-link-with (turtle ((tar + i) mod N)) ] ] ;; rewiring ask links [ let if_rewired false if (random-float 1) < beta[ let node1 end1 if [ count link-neighbors ] of node1 < (N - 1) [ let node2 one-of turtles with [ (self != node1) and (not link-neighbor? node1)] ask node1 [ create-link-with node2 [ set if_rewired true ] ] ] ] if (if_rewired)[ die ] ] ][ display user-message (word "Select k < N") ] ask turtles [ set label-color black ] set q-voters nobody set-shape-visible end to set-target set-shape-visible ask links [set color gray set thickness 0.1] set target random N ask turtle target [ set size size_highlight ifelse pub = 1 [ ifelse priv = 1 [set shape "pp"] [set shape "pm"] ][ ifelse priv = 1 [set shape "mp"] [ set shape "mm"] ] ask my-links [set color black set thickness 0.2] ] set q-voters nobody end to q-panel if q-voters != nobody [ ask q-voters[ set size size_normal ] ] ask turtle target [ set size size_highlight if (count link-neighbors) >= q [ set q-voters n-of q link-neighbors ask q-voters [set size size_highlight] ] ] end to act clear-output ;ask q-voters [set size size_highlight] ifelse random-float 1 < p [ ;; independence output-print "Independence" ask turtle target [set pub priv] ] [ ;; conformity ifelse q-voters = nobody [ display user-message (word "Select q-panel") ] [ output-print "Conformity" ask turtle target [ ifelse priv = pub [ output-print "Compliance" if (all? q-voters [pub = 1]) [ask turtle target [set pub 1]] if (all? q-voters [pub = -1]) [ask turtle target [set pub -1]] ] [ output-print "Disinhibitory contagion" ifelse priv = 1 [if (any? q-voters with [pub = 1]) [ask turtle target [set pub 1]]] [if (any? q-voters with [pub = -1]) [ask turtle target [set pub -1]]] ] ] ] ] ask turtle target [ ifelse pub = 1 [ ifelse priv = 1 [set shape "pp"][set shape "pm"] ][ ifelse priv = 1 [set shape "mp"][set shape "mm"] ] ] end to think clear-output ifelse random-float 1 < p [ ;; independence output-print "Independence" ask turtle target [ ifelse random-float 1.0 < 0.5 [set priv 1][set priv -1] ] ] [ ;; conformity ifelse q-voters = nobody [ display user-message (word "Select q-panel") ] [ output-print "Conformity" ask turtle target [ ifelse pub = 1 [ if (all? q-voters [pub = 1]) [ask turtle target [set priv 1]] ] [ if (all? q-voters [pub = -1]) [ask turtle target [set priv -1]] ] ] ] ] ask turtle target [ ifelse pub = 1 [ ifelse priv = 1 [set shape "pp"][set shape "pm"] ][ ifelse priv = 1 [set shape "mp"][set shape "mm"] ] ] end to set-shape-visible ask turtles [set size size_normal] ask turtles [ ifelse pub = 1 [ set shape "p" ][ set shape "m" ] ] end to set-shape ask turtles [set size size_normal] ask turtles [ ifelse pub = 1 [ ifelse priv = 1 [set shape "pp"] [set shape "pm"] ][ ifelse priv = 1 [set shape "mp"] [ set shape "mm"] ] ] end to go-AT ask links [set color gray set thickness 0.1] set-shape set target random N ask turtle target [ ;; ACT ask my-links [set color black set thickness 0.2] ifelse random-float 1.0 < p [ ;; independence ask turtle target [set pub priv] ] [ ;; conformity ifelse (count link-neighbors) >= q [set q-voters n-of q link-neighbors][set q-voters nobody] if q-voters != nobody [ ifelse priv = pub [ if (all? q-voters [pub = 1]) [ask turtle target [set pub 1]] if (all? q-voters [pub = -1]) [ask turtle target [set pub -1]] ] [ ifelse priv = 1 [if (any? q-voters with [pub = 1]) [ask turtle target [set pub 1]]] [if (any? q-voters with [pub = -1]) [ask turtle target [set pub -1]]] ] ] ] ;; THINK ifelse random-float 1 < p [ ;; independence ask turtle target [ ifelse random-float 1.0 < 0.5 [set priv 1][set priv -1] ] ] [ ;; conformity ifelse (count link-neighbors) >= q [set q-voters n-of q link-neighbors] [set q-voters nobody] if q-voters != nobody [ ifelse pub = 1 [if (all? q-voters [pub = 1]) [ask turtle target [set priv 1]]] [if (all? q-voters [pub = -1]) [ask turtle target [set priv -1]]] ] ] ] set diss ((count turtles with [priv = 1 and pub = -1] + count turtles with [priv = -1 and pub = 1]) / N) if(ticks > 1000) [ ifelse (length diss_1000 >= 1000) [ set pub_p_1000 lput (count turtles with [pub = 1] / N) pub_p_1000 set pub_p_1000 (but-first pub_p_1000) set avg_pub ((sum pub_p_1000) / 1000) set priv_p_1000 lput (count turtles with [priv = 1] / N) priv_p_1000 set priv_p_1000 (but-first priv_p_1000) set avg_priv ((sum priv_p_1000) / 1000) set diss_1000 lput diss diss_1000 set diss_1000 (but-first diss_1000) set avg_diss ((sum diss_1000) / 1000) ] [ set pub_p_1000 lput (count turtles with [pub = 1] / N) pub_p_1000 set priv_p_1000 lput (count turtles with [priv = 1] / N) priv_p_1000 set diss_1000 lput diss diss_1000 ] ] tick end to go-TA ask links [set color gray set thickness 0.1] set-shape set target random N ask turtle target [ ;; THINK ifelse random-float 1 < p [ ;; independence ask turtle target [ ifelse random-float 1.0 < 0.5 [set priv 1][set priv -1] ] ] [ ;; conformity ifelse (count link-neighbors) >= q [set q-voters n-of q link-neighbors] [set q-voters nobody] if q-voters != nobody [ ifelse pub = 1 [if (all? q-voters [pub = 1]) [ask turtle target [set priv 1]]] [if (all? q-voters [pub = -1]) [ask turtle target [set priv -1]]] ] ] ;; ACT ask my-links [set color black set thickness 0.2] ifelse random-float 1.0 < p [ ;; independence ask turtle target [set pub priv] ] [ ;; conformity ifelse (count link-neighbors) >= q [set q-voters n-of q link-neighbors][set q-voters nobody] if q-voters != nobody [ ifelse priv = pub [ if (all? q-voters [pub = 1]) [ask turtle target [set pub 1]] if (all? q-voters [pub = -1]) [ask turtle target [set pub -1]] ] [ ifelse priv = 1 [if (any? q-voters with [pub = 1]) [ask turtle target [set pub 1]]] [if (any? q-voters with [pub = -1]) [ask turtle target [set pub -1]]] ] ] ] ] set diss ((count turtles with [priv = 1 and pub = -1] + count turtles with [priv = -1 and pub = 1]) / N) if(ticks > 1000) [ ifelse (length diss_1000 >= 1000) [ set pub_p_1000 lput (count turtles with [pub = 1] / N) pub_p_1000 set pub_p_1000 (but-first pub_p_1000) set avg_pub ((sum pub_p_1000) / 1000) set priv_p_1000 lput (count turtles with [priv = 1] / N) priv_p_1000 set priv_p_1000 (but-first priv_p_1000) set avg_priv ((sum priv_p_1000) / 1000) set diss_1000 lput diss diss_1000 set diss_1000 (but-first diss_1000) set avg_diss ((sum diss_1000) / 1000) ] [ set pub_p_1000 lput (count turtles with [pub = 1] / N) pub_p_1000 set priv_p_1000 lput (count turtles with [priv = 1] / N) priv_p_1000 set diss_1000 lput diss diss_1000 ] ] tick end
There is only one version of this model, created 8 months ago by Barbara Kamińska.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
q-voter model (expressed & private opinions).png | preview | Preview for 'q-voter model (expressed & private opinions)' | 8 months ago, by Barbara Kamińska | Download |
This model does not have any ancestors.
This model does not have any descendants.