Agent_Zero

No preview image

1 collaborator

Default-person Joshua Epstein (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0.2 • Viewed 344 times • Downloaded 25 times • Run 0 times
Download the 'Agent_Zero' 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

          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
          ;;               AGENT_ZERO
          ;;    MOVIE 3 Parable 1 Code. Version 1.0
          ;;           Agent_Zero Joins
          ;;
          ;;           Joshua M. Epstein
          ;;            February 2010
          ;;         Revised November 2012
          ;;       Book Sliders [45,0,6,1,1]
          ;;             Book Seed 1
          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;extensions [vid]
globals[                         ; The more important of these are set w/sliders.
  inactive-color
  active-color
  destroyed-color
  link-color
  deactivation-rate              ; Probablitity a patch returns to inactive from active
  maximum-stopping-time
]

directed-link-breed [red-links red-link]

links-own [weight]

turtles-own [
            affect
            learning_rate
            lambda
            delta             ; Generalized Rescorla-Wagner exponent
            threshold
            event_count
            disposition
            probability
            memory
            ]

to use-new-seed                                  ; Seed generated by NetLogo
  let my-seed new-seed
  output-print word "Generated seed: " my-seed   ; Print in Command Center window
  random-seed my-seed                            ; Use the new seed
end 

to use-seed-from-user                            ; Queries user for seed
  let my-seed read-from-string user-input "Enter a random seed (an integer):"
  output-print word "User-entelink-colorseed: " my-seed
  random-seed my-seed
end 

to setup-globals
  set inactive-color yellow      ; Small random number is added, in setup-patches, for visualization.
  set active-color orange + 1
  set destroyed-color red - 3
  set deactivation-rate 8
  set link-color red
  set maximum-stopping-time 50000
end 

to setup-links

   ask turtle 0 [ create-red-link-to turtle 1]
                 ask red-link 0 1 [
                 set color link-color
                 set weight 0.3]
   ask turtle 0 [ create-red-link-to turtle 2]
                 ask red-link 0 2 [
                 set color link-color
                 set weight 0.3]
   ask turtle 1 [ create-red-link-to turtle 0]
                 ask red-link 1 0 [
                 set color link-color
                 set weight 0.3]
   ask turtle 1 [ create-red-link-to turtle 2]
                 ask red-link 1 2 [
                 set color link-color
                 set weight 0.3]
   ask turtle 2 [ create-red-link-to turtle 0]
                 ask red-link 2 0 [
                 set color link-color
                 set weight 0.3]
   ask turtle 2 [ create-red-link-to turtle 1]
                 ask red-link 2 1 [
                 set color link-color
                 set weight 0.3]
end 

to setup
  clear-all
  ;use-new-seed   .
  use-seed-from-user
  setup-globals
  setup-patches
  setup-turtles
  setup-links
  ;setup-movie   ; Uncomment to make movie
  reset-ticks
end 

;;to setup-movie
;;   vid:start-recorder
;;   vid:record-view      ; Show the initial state
;;   repeat 750           ; Movie length in frames
;;    [ go
;;    vid:record-view ]
;;   vid:save-recording "out"
;;end

to setup-turtles
  set-default-shape turtles "person"
  create-turtles 3
  ask turtle 0 [
                setxy -9 -9      ; For random positions use random x-cor  random y-cor
                set color blue
                set affect 0.001 ; For delta > 0, if V(0)=0, then V(t)=0 for all t. Hence, small positive init.
                set delta 0
                set lambda 1
                set learning_rate .1
                set threshold .5
                set event_count 0
                set disposition 0
                set probability 0
                set memory []
                  repeat memory_length
                    [set memory lput random-float 0 memory]
                ;set memory [0]    ; This recovers the memory one original model, w/initial estimate the entry.
                ;set memory [0 0 0 0]
                ;set label who      ; Uncomment to have agent number visible
                ]

  ask turtle 1 [
                setxy  5 5
                set color blue
                set affect 0.001
                set delta 0
                set lambda 1
                set learning_rate .1
                set threshold .5
                set event_count 0
                set disposition 0
                set probability 0
                ;set memory [ 1 3 5 7 8]
                set memory []
                  repeat memory_length
                    [set memory lput random-float 0 memory]
                ; show memory
                ; set label who
                ]
  ask turtle 2 [
                setxy 3 9
                set color blue
                set affect 0.001
                set delta 0
                set lambda 1
                set learning_rate .1
                set threshold .5
                set event_count 0
                set disposition 0
                set probability 0
                set memory []
                  repeat memory_length
                    [set memory lput random-float 0 memory]
                ;set memory [0 0]
                ;set label who
              ]
end 

to setup-patches
  ask patches [set pcolor inactive-color + random 2]
end 

to go                              ; Corresponds to 'main' in C/C++
  if ticks >= maximum-stopping-time [stop]
  move-turtles
  activate-patches
  update-event_count
  update-affect
  update-probability
  update-disposition
  take-action
  deactivate-patches ; Turns them back to inactive from active.
  do-plots1
  do-plots2
  do-plots3
  tick
end 

to update-event_count
ask turtles[
    if pcolor = active-color [set event_count event_count + 1]
           ]
end 

to update-affect ; Standard RW for delta=0. Standard logistic for delta=1. General S-curves : 0 < delta < 1
   ask turtles [
        if pcolor = active-color
           [set affect affect + (learning_rate * (affect ^ delta) * (lambda - affect))]
        if pcolor != active-color
           [set affect affect + (learning_rate * (affect ^ delta) * extinction_rate *(0 - affect))]
               ]                           ; Standard RW extinction for extinction_rate=1. Typically use < 1.
end 

to update-probability
 ask turtles[
 let current_probability
        (count patches in-radius spatial_sample_radius with [pcolor = active-color]/(count patches in-radius spatial_sample_radius))
 set memory but-first memory                                      ; Drops leftmost value
 set memory lput current_probability memory                       ; Adds current_prob as rightmost value
 set probability mean memory
 ;set probability median memory        ; Uncomment this, and comment out mean to switch to moving median, and vice versa.
   ]
end 

to update-disposition   ; Uses Disposition net of threshold
 ask turtle 0 [
   set disposition affect + probability + [weight] of red-link 1 0 * ([affect] of turtle 1 + [probability] of turtle 1) +
                                          [weight] of red-link 2 0 * ([affect] of turtle 2 + [probability] of turtle 2) - threshold] ; NetLogo scoping interprets the last as : [threshold] of turtle 0
 ask turtle 1 [
   set disposition affect + probability + [weight] of red-link 0 1 * ([affect] of turtle 0 + [probability] of turtle 0) +
                                          [weight] of red-link 2 1 * ([affect] of turtle 2 + [probability] of turtle 2) - threshold]
 ask turtle 2 [
   set disposition affect + probability + [weight] of red-link 0 2 * ([affect] of turtle 0 + [probability] of turtle 0) +
                                          [weight] of red-link 1 2 * ([affect] of turtle 1 + [probability] of turtle 1) - threshold]
end 

to move-turtles
  ask turtles with [who != 0] [  ; This immobilizes Agent_0
    right random 360             ; Adopt random heading
    forward 1
    ]
end 

to take-action
  ask turtles [
    if disposition > 0 [ask patches in-radius action_radius [set pcolor destroyed-color]]
    ]
end 

to activate-patches  ; Patches in specified sector that are not dead
 ask patches with [pxcor > -5 and pycor > -2]
      [if random 1000 < attack_rate and pcolor != destroyed-color [set pcolor active-color]]
end 

to deactivate-patches
 ask patches with [pxcor > -5 and pycor > -2]
      [if random 100 < deactivation-rate and pcolor != destroyed-color [set pcolor inactive-color + random 2]]
end 

to do-plots1
    set-current-plot "Disposition"
    set-current-plot-pen "turtle 0"
    plot [disposition] of turtle 0
    set-current-plot-pen "turtle 1"
    plot [disposition] of turtle 1
    set-current-plot-pen "turtle 2"
    plot [disposition] of turtle 2
end 

to do-plots2
    set-current-plot "Probability"
    set-current-plot-pen "turtle 0"
    plot [probability] of turtle 0
    set-current-plot-pen "turtle 1"
    plot [probability] of turtle 1
    set-current-plot-pen "turtle 2"
    plot [probability] of turtle 2
end 

to do-plots3
    set-current-plot "Affect"
    set-current-plot-pen "turtle 0"
    plot [affect] of turtle 0
    set-current-plot-pen "turtle 1"
    plot [affect] of turtle 1
    set-current-plot-pen "turtle 2"
    plot [affect] of turtle 2
end 

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

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.