Macros for marginalization

Macros for marginalization preview image

1 collaborator

Default-person Charles Lassiter (Author)

Tags

culture 

Tagged by Charles Lassiter almost 6 years ago

Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0.1 • Viewed 190 times • Downloaded 18 times • Run 0 times
Download the 'Macros for marginalization' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

breed [qms qm]
breed [confs conf]
breed [rebels rebel]
breed [devs dev]
globals [
  trait-list
  confs-culture
  qms-culture
  rebels-culture
  devs-culture
  ;; from here to the end of the globals list are variables that are needed for analysis of the model
  initial-confs
  initial-devs
  initial-rebels
  initial-qms
  qms-diff
  confs-diff
  rebels-diff
  devs-diff
  conf-qm
  dev-qm
  rebel-dev
  conf-dev
  rebel-qm
  conf-rebel
  c-pop
  qm-pop
  d-pop
  r-pop
  ]
turtles-own [
  my-culture
  partner
  change
  changeable?
  total-partners
  generation]

to setup
  ca
  reset-ticks
  set-default-shape turtles "circle"

  let n 0
  set trait-list [] ;; compile list of traits. this wil be used later for compiling cultures.
  repeat 60 [
    set trait-list lput n trait-list
    set n n + 1
    ]
  ask patches with [pxcor > 0 and pycor > 0][ set pcolor white]
  ask patches with [pxcor <= 0 and pycor > 0][ set pcolor gray]
  ask patches with [pxcor <= 0 and pycor <= 0][ set pcolor pink ]
  ask patches with [pxcor > 0 and pycor <= 0] [set pcolor violet]
  make-turtles
  ask turtles [ set partner nobody ]
end 

to go
  tick
  clear-links
interact-step-1
analyze-cultures
switch-breeds
die-and-replace
output-similarities
output-diff

if ((mean [generation] of turtles) >= 2) and ((mean [total-partners] of turtles) >= 500) [stop]
end 

to make-turtles  ;;; creates turtles, assigns to breeds, assigns primary traits and secondary traits.
                 ;;; One is hatched, creates the rest, and then dies.
  create-confs 1 [set color orange set size .5
    set confs-culture [ 1 2 3 4 5 16 19 20]
    set initial-confs confs-culture
    hatch 120 [
      set my-culture [confs-culture] of self
      set-culture
      move-to one-of patches with [pcolor = violet]
      set total-partners 0
      set change 0
      ]
    die]

  create-qms 1 [set color green set size .5
    set qms-culture [ 1 2 3 7 10 13 17 18 ]
    set initial-qms qms-culture
    hatch 2 [
      set my-culture [qms-culture] of self
      set-culture
      move-to one-of patches with [pcolor = white]
      set total-partners 0
      set change 0
    ]
    die]


  create-rebels 1 [set color black set size .5
    set rebels-culture [ 4 15 7 8 9 14 17 18 ]
    set initial-rebels rebels-culture
    hatch 8 [
      set my-culture [rebels-culture] of self
      set-culture
      move-to one-of patches with [pcolor = pink]
      set total-partners 0
      set change 0
    ]
    die]

  create-devs 1 [set color red set size .5
    set devs-culture [ 6 8 9 11 12 13 21 22 ]
    set initial-devs devs-culture
    hatch 70 [
      set my-culture [devs-culture] of self
      set-culture
      move-to one-of patches with [pcolor = grey]
      set total-partners 0
      set change 0
    ]
    die]
end 

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;; these are the procedures for giving the turtles their cultures.

to set-culture
  ifelse (num-traits - length my-culture) > 0 [
    repeat (num-traits - length my-culture) [ pick-new-trait ]] [
    while [length my-culture > num-traits] [set my-culture remove-item random (length my-culture) my-culture]] ;; defensive coding
end 

to pick-new-trait ;; fills out secondary traits and ensures no doubles of traits.
 let new-trait random 38 + 22
    ifelse not member? new-trait my-culture [
          set my-culture lput new-trait my-culture][
          pick-new-trait]
end 


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; now we write the code for the turtles to interact

to interact-step-1
 ask turtles [
   let p one-of my-culture
   let potential-partners other turtles with [member? p my-culture] ;; sets agentset to turtles with value p
 ;   show potential-partners
   set partner one-of potential-partners
 ;   show partner
   if (partner != nobody) [
   create-link-with partner [set color 125]
    ; show count link-neighbors
   set total-partners total-partners + count my-links
    ;  show total-partners

     if resistance-level = "low" [low-interact-step-2]
     if resistance-level = "mid" [mid-interact-step-2]
     if resistance-level = "high" [hi-interact-step-2]
   ]
]
end 

to low-interact-step-2
if is-dev? self [
   if is-qm? partner and random-float 1 > .95 [ move-traits]
   if is-rebel? partner and random-float 1 > .4 [ move-traits]
   if is-conf? partner and random-float 1 > .9 [ move-traits]
   if is-dev? partner [ move-traits]
 ]
if is-conf? self[
  if is-qm? partner and random-float 1 > .95 [ move-traits]
  if is-rebel? partner and random-float 1 > .9 [ move-traits]
  if is-dev? partner [] ;a conf will never take on properties of a dev
  if is-conf? partner [ move-traits]
]
if is-qm? self [
   if is-conf? partner [] ;; a qm will never take on properties of a dev
   if is-rebel? partner [] ;; a qm will never take on properties of a dev
   if is-dev? partner [] ;; a qm will never take on properties of a dev
   if is-qm? partner [ move-traits]
 ]
 if is-rebel? self [
   if is-qm? partner and random-float 1 > .8 [ move-traits]
   if is-conf? partner [] ;; a rebel will never take on properties of a conf
   if is-dev? partner [] ;; a rebel will never take on properties of a dev
   if is-rebel? partner [ move-traits]
 ]
end 

to mid-interact-step-2
if is-dev? self [
   if is-qm? partner and random-float 1 > .97 [ move-traits]
   if is-rebel? partner and random-float 1 > .6 [ move-traits]
   if is-conf? partner and random-float 1 > .925 [ move-traits]
   if is-dev? partner [ move-traits]
 ]
if is-conf? self[
  if is-qm? partner and random-float 1 > .9625[ move-traits]
  if is-rebel? partner and random-float 1 > .925 [ move-traits]
  if is-dev? partner and random-float 1 > .8 [ move-traits]
  if is-conf? partner [ move-traits]
]
if is-qm? self [
   if is-conf? partner [] ;; a qm will never take on properties of a conf
   if is-rebel? partner [] ;; a qm will never take on properties of a rebel
   if is-dev? partner [] ;; a qm will never take on properties of a dev
   if is-qm? partner [ move-traits]
 ]
 if is-rebel? self [
   if is-qm? partner and random-float 1 > .85 [ move-traits]
   if is-conf? partner [] ;; a rebel will never take on properties of a conf
   if is-dev? partner [] ;; a rebel will never take on properties of a dev
   if is-rebel? partner [ move-traits]
 ]
end 

to hi-interact-step-2
if is-dev? self [
   if is-qm? partner and random-float 1 > .99 [ move-traits]
   if is-rebel? partner and random-float 1 > .8 [ move-traits]
   if is-conf? partner and random-float 1 > .95 [ move-traits]
   if is-dev? partner [ move-traits]
 ]
if is-conf? self[
  if is-qm? partner and random-float 1 > .975 [ move-traits]
  if is-rebel? partner and random-float 1 > .95 [ move-traits]
  if is-dev? partner and random-float 1 > .6 [ move-traits]
  if is-conf? partner [ move-traits]
]
if is-qm? self [
   if is-conf? partner [] ;; a qm will never take on properties of a conf
   if is-rebel? partner [] ;; a qm will never take on properties of a rebel
   if is-dev? partner [] ;; a qm will never take on properties of a dev
   if is-qm? partner [ move-traits]
 ]
 if is-rebel? self [
   if is-qm? partner and random-float 1 > .9 [ move-traits]
   if is-conf? partner [] ;; a rebel will never take on properties of a conf
   if is-dev? partner [] ;; a rebel will never take on properties of a dev
   if is-rebel? partner [ move-traits]
 ]
end 

to move-traits ;; upon finding a partner, the calling agent replaces randomly chosen value with a randomly chosen value from the called agent.
  let n one-of [my-culture] of partner
  set my-culture replace-item (random num-traits) my-culture n
end 

to analyze-cultures
  let full-confs-culture (compile-cultures confs confs-culture)
  let full-qms-culture (compile-cultures qms qms-culture)
  let full-rebels-culture (compile-cultures rebels rebels-culture)
  let full-devs-culture (compile-cultures devs devs-culture)

  let n1 (new-culture full-confs-culture)
  let n2 (new-culture full-qms-culture)
  let n3 (new-culture full-rebels-culture)
  let n4 (new-culture full-devs-culture)

  if length n1 >= 8 [set confs-culture n1 ]
  if length n2 >= 8 [set qms-culture n2 ]
  if length n3 >= 8 [set rebels-culture n3]
  if length n4 >= 8 [set devs-culture n4]
end 

to-report compile-cultures [input-breed input-culture] ;; this reporter takes the traits from agents of input-breed and compiles them into one list
  set input-culture [] ;; empties out the input culture
  foreach trait-list [ ?1 ->
    ask turtles with [breed = input-breed] [
      if member? ?1 my-culture [set input-culture lput ?1 input-culture]
    ]
  ]
    report input-culture
end 

to-report new-culture [ culture-list ] ;; a reporter. for a breed B, takes as input the union of my-cultures for turtles of B.

  let temp-list [ ] ;; empty list that will report the 6 most frequently occuring values in culture-list
  let copy-list culture-list ;; list that takes culture-list as input

  let n modes copy-list ;;set n to the most frequently occuring value of the copy-list (i.e. the input list)
  if length n > 1 [repeat (length n) - 1 [set n remove-item (random length n) n]] ;; make sure n has only one item
  foreach n [ ?1 -> if member? ?1 copy-list [set copy-list remove ?1 copy-list] ] ;; removes n from the copy-list
  set temp-list n

  repeat 7 [
    set n modes copy-list ;;set the temp-list to the most frequently occuring value of the copy-list (i.e. the input list)
    if length n > 1 [ ;; make sure n has only one item.
      repeat (length n) - 1 [
        set n remove-item (random length n) n   ;;if there are ties for the mode, losers are chosen at random until one is left.
      ]
    ]
    foreach n [ ?1 -> ;; remove the mode from the copy-list
      if member? ?1 copy-list [
        set copy-list remove ?1 copy-list
      ]
    ] ;; add the mode to the temp-list
    foreach n [ ?1 ->
      if not member? ?1 temp-list [
        set temp-list lput ?1 temp-list
      ]
    ]
  ]
  report temp-list
end 

to switch-breeds ;; for a turtle to switch breeds, its my-culture should have the 6 core traits of the new breed.
    ask turtles [

    set changeable? true ;; turtles can change breeds at the start of this procedure. once they've gone through the 'make-changes' routine, they can't change until the next time step.

    let p1s 0 ;; these are tickers to keep track of how many items in my-culture are in each BREED-culture
    let p2s 0
    let p3s 0
    let p4s 0
    let short-my-culture remove-duplicates my-culture
                                                      ;; philosophical question: when determining if an agent should belong to a culture, are we interested in matches on types or tokens?
                                                      ;; if you're a type-person, comment the line following these notes and uncomment the one preceding.
                                                      ;; if you're a token-person, comment the line preceding these notes and uncomment the following.
                                                      ;; the results are different depending on which is run.
   ; let short-my-culture my-culture
    foreach short-my-culture [ ?1 ->
      if member? ?1 confs-culture [set p1s p1s + 1]
      if member? ?1 qms-culture [set p2s p2s + 1]
      if member? ?1 rebels-culture [set p3s p3s + 1]
      if member? ?1 devs-culture [ set p4s p4s + 1]
    ]
    if p2s >= 7 and p2s = p3s and changeable? = true [ifelse random 2 = 0 [set breed qms make-changes] [set breed rebels make-changes]] ;; check for any ties with cultures and then make changes at random
    if p2s >= 7 and p2s = p4s and changeable? = true [ifelse random 2 = 0 [set breed qms make-changes] [set breed devs make-changes]]
    if p3s >= 7 and p3s = p4s and changeable? = true [ifelse random 2 = 0 [set breed rebels make-changes] [set breed devs make-changes]]
    if p1s >= 7 and p1s = p2s and changeable? = true [ifelse random 2 = 0 [set breed confs make-changes] [set breed qms make-changes]]
    if p1s >= 7 and p1s = p3s and changeable? = true [ifelse random 2 = 0 [set breed confs make-changes] [set breed rebels make-changes]]
    if p1s >= 7 and p1s = p4s and changeable? = true [ifelse random 2 = 0 [set breed confs make-changes] [set breed devs make-changes]]

    if (p1s >= 7 or p2s >= 7 or p3s >= 7 or p4s >= 7) [ ;; if tickers exceed 8
      if (p3s > p1s and p3s > p2s and p3s > p4s) and changeable? = true [set breed rebels make-changes]
      if (p4s > p1s and p4s > p2s and p4s > p3s) and changeable? = true [set breed devs make-changes]
      if (p1s > p2s and p1s > p3s and p1s > p4s) and changeable? = true [set breed confs make-changes]  ;; then check for which culture best fits the agent
      if (p2s > p1s and p2s > p3s and p2s > p4s) and changeable? = true [set breed qms make-changes]

    ]

  ]
end 

to make-changes ;; a little tidying up for the visuals
  if [breed] of self = confs [
    set color orange
    set change change + 1
    move violet
    if any? turtles-here [move violet]
    set changeable? false
  ]
  if [breed] of self = qms [
    set color green
          set change change + 1
          move white
          if any? turtles-here [move white]
          set changeable? false
  ]
  if [breed] of self = devs[
  set color red
          set change change + 1
          move gray
          if any? turtles-here [move grey]
          set changeable? false
]
if [breed] of self = rebels [
  set color black
          set change change + 1
          move pink
          if any? turtles-here [move pink]
          set changeable? false
]
end 

to move [clr]
    move-to one-of patches with [pcolor = clr]
end 

to output-similarities ;;  checks for similarities among cultures.

  let a sort remove-duplicates (sentence confs-culture qms-culture)
  set conf-qm 2 - (length a / 8)

  let b sort remove-duplicates (sentence devs-culture qms-culture)
  set dev-qm 2 - (length b / 8)

  let c sort remove-duplicates (sentence confs-culture devs-culture)
  set conf-dev 2 - (length c / 8)

  let d sort remove-duplicates (sentence rebels-culture devs-culture)
  set rebel-dev 2 - (length d / 8)

  let f remove-duplicates (sentence confs-culture rebels-culture)
  set conf-rebel 2 - (length f / 8)

  let g remove-duplicates (sentence rebels-culture qms-culture)
  set rebel-qm 2 - (length g / 8)
end 

to output-diff ;; checks for difference from the starting point
  set-current-plot "difference from initial culture"

  let iqms remove-duplicates (sentence initial-qms qms-culture)
  ;output-type "initial-current qms difference: "
  set qms-diff   (1 - (2 - (length iqms / 8)))
  set-current-plot-pen "qmd"
  set-plot-pen-color green
  plot qms-diff

  let id remove-duplicates (sentence initial-devs devs-culture)
  ;output-type "initial-current confs difference: "
  set devs-diff (1 - (2 - (length id / 8)))
  set-current-plot-pen "dd"
  set-plot-pen-color red
  plot devs-diff

  let ir remove-duplicates (sentence initial-rebels rebels-culture)
  ;output-type "initial-current confs difference: "
  set rebels-diff (1 - (2 - (length ir / 8)))
  set-current-plot-pen "rd"
  set-plot-pen-color black
  plot rebels-diff

   let ic remove-duplicates (sentence initial-confs confs-culture)
  ;output-type "initial-current confs difference: "
  set confs-diff (1 - (2 - (length ic / 8)))
  set-current-plot-pen "cd"
  set-plot-pen-color orange
  plot confs-diff

  set-current-plot "populations"

  set-current-plot-pen "c"
  set-plot-pen-color orange
  set c-pop (count confs / count turtles)
  plot c-pop

  set-current-plot-pen "qm"
  set-plot-pen-color green
  set qm-pop (count qms / count turtles)
  plot qm-pop

  set-current-plot-pen "d"
  set-plot-pen-color red
  set d-pop (count devs / count turtles)
  plot d-pop

  set-current-plot-pen "r"
  set-plot-pen-color black
  set r-pop (count rebels / count turtles)
  plot r-pop
end 

to die-and-replace
  ask turtles [
    if total-partners >= 1000 [
      hatch 1 [
        set breed [breed] of myself
        set color [color] of myself
        set xcor [xcor] of myself
        set ycor [ycor] of myself
        set change 0
        set total-partners 0
        if breed = confs [
          set my-culture n-of random 9 confs-culture
          set-culture
          set generation generation + 1
        ]
        if breed = qms [
          set my-culture n-of random 9 qms-culture
          set-culture
          set generation generation + 1
        ]
        if breed = devs [
          set my-culture n-of random 9 devs-culture
          set-culture
          set generation generation + 1
        ]
        if breed = rebels [
          set my-culture n-of random 9 rebels-culture
          set-culture
          set generation generation + 1
        ]
      ]
      die
    ]
  ]
end 

There is only one version of this model, created almost 6 years ago by Charles Lassiter.

Attached files

File Type Description Last updated
fpsyg-09-00812.pdf pdf "Diversity and Resistance to Change," Frontiers in Psychology (2018) almost 6 years ago, by Charles Lassiter Download
Macros for marginalization.png preview Preview for 'Macros for marginalization' almost 6 years ago, by Charles Lassiter Download

This model does not have any ancestors.

Children:

Graph of models related to 'Macros for marginalization'