⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ---social-preference.nlogo

📁 NETLOGO
💻 NLOGO
📖 第 1 页 / 共 2 页
字号:
;; edges and nodes are both turtles, nodes are acquirersbreeds [edges nodes];;;;;;;;;;;;;;;;; Variables ;;;;;;;;;;;;;;;;;nodes-own[  ;; stores the list of nodes neighbor-nodes to this node  neighbor-nodes  ;; these are the net forces on a node in the x and y direction;  ;; they are used to do the layout  force-x  force-y  node-size  acquirer-grammar-state  perceived-grammar-state   sample-set   network-sample-set  random-sample-set  sample-set2  mylist mylist2 mylist-temp random-mylist   gamma ]patches-own [counterarena-grammar-state];; An edge connects two nodes, A and B.  The direction of the edges;; doesn't matter in this model, so it doesn't matter which node;; is A and which is B.edges-own [a b]globals[  new-node  ;; the last node we created  num-patches  patch-count  arena-mean  utt/acq];;;;;;;;;;;;;;;;;;;;;;;;;;; Setup Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;to setup  ca  set-default-shape nodes "circle"  set-default-shape edges "line"  ask patches   [  set counter 0  set arena-grammar-state 0  set pcolor green + random 5  ]  diffuse pcolor .9  ;; make the initial network of two nodes and an edge  make-node ;; first node  let first-node new-node  make-node ;; second node  make-edge new-node first-node ;; make the edgeend;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Main Procedure for network ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;to go  ;; we don't want the display to update while we're in the middle  ;; of updating stuff, so we use no-display/display to freeze/unfreeze  no-display  ;; new edge is green, old edges are gray  ask edges [ set color gray ]  let partner find-partner       ;; find a partner for the new node  make-node                      ;; add the new node  make-edge new-node partner     ;; connect it to the partner we picked before    display  set patch-count (count patches with [counter = 1])end;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Runtime Procedures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; used for creating a new nodeto make-nodeask random-n-of 1 patches [ifelse (patch-count < (count patches ))  [  ifelse (((value-from self [counter]) = 0))     [    sprout-nodes 1      [        set node-size .3        set size node-size        set color red        set counter-of patch-here 1        set new-node self ;; set the new-node global        ;; initially, nodes have no connecting edges        set neighbor-nodes []  ;; empty list      ]    ]    [    make-node    ]  ]  [   if user-yes-or-no?  "Social network is complete - evolve?"     [ setup-evolve ]    stop  ]]end;; This code is borrowed from Lottery Example, from the Code Examples;; section of the Models Library.;; The idea behind the code is a bit tricky to understand.;; Basically we take the sum of the degrees (number of connections);; of the nodes, and that's how many "tickets" we have in our lottery.;; Then we pick a random "ticket" (a random number).  Then we step;; through the nodes to figure out which node holds the winning ticket.to-report find-partner  let total random-float sum values-from nodes [length neighbor-nodes]  let partner nobody  ;; reporter procedures always run without interruption,  ;; so we don't need "without-interruption" in order to  ;; make the turtles go one at a time  ask nodes  [    ;; if there's no winner yet...    if partner = nobody    [      ifelse length neighbor-nodes > total        [ set partner self ]        [ set total total - (length neighbor-nodes) ]    ]  ]  report partnerend;;;;;;;;;;;;;;;;;;;;;;;;;; Edge Operations ;;;;;;;;;;;;;;;;;;;;;;;;;;;; connects the two nodesto make-edge [node1 node2]  if member? node1 neighbor-nodes-of node2  [    user-message "There is already an edge between " + node1 + " and " + node2    stop  ]  create-custom-edges 1  [    set color green    set a node1    set b node2    reposition-edge  ]  ;; add each node to the other's neighbor-nodes list  set neighbor-nodes-of node2 fput node1 neighbor-nodes-of node2  set neighbor-nodes-of node1 fput node2 neighbor-nodes-of node1end;; repositions and resizes the edge according to the position of the nodesto reposition-edge  ;; edge procedure  setxy (xcor-of a) (ycor-of a)  set size distance-nowrap b  ;; watch out for special case where a and b are  ;; at the same place  if size != 0  [    ;; position edge at midpoint between a and b    set heading towards-nowrap b    jump size / 2  ]end;; resize-nodes, change back and forth from size based on degree to a size of 1to resize-nodes  ifelse ( not (any? nodes with [size > node-size]) )  [    ;; a node is a circle with diameter determined by    ;; the SIZE variable; using SQRT makes the circle's    ;; area proportional to its degree and it is divided by two to reduce size on-screen    ask nodes [ set size ((sqrt length neighbor-nodes) / 2)]  ]  [    ask nodes [ set size node-size ]  ]end;;;;;;;;;;;;;;;;;;;; setup-evolve ;;;;;;;;;;;;;;;;;;;;to setup-evolve     initialize-arena     set num-patches screen-size-x * screen-size-yend;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Main Procedure for evolve  ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;to go-evolveask nodes     [      sample-arena-hybrid    ]update-colorsspeakdo-plotsendto initialize-arenaask nodes  [  set acquirer-grammar-state .5  set color red  ifelse (length neighbor-nodes > social-bias)        [        set arena-grammar-state-of patch-here ( 0 )        set pcolor-of patch-here black        ]        [        set arena-grammar-state-of patch-here ( 1 )        set pcolor-of patch-here white        ]  ] end;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;HYBRID SAMPLING PROCEDURE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;to sample-arena-hybrid ;observer procedureset gamma .01  ;this is the value from Yang 2002 used to smooth individual acquisitionset mylist2 []set sample-set2 []    ;acquirers connected to node are sampled and retained as "network-sample-set". set network-sample-set neighbor-nodes-of self;a random set of speakers is sampled and retained as "random-sample-set" as in hybrid model.      set random-sample-set random-n-of (round((proportion-to-sample) * num-patches)) patches ;The values of "arena-grammar-state" from sample-set are put into "mylist"      set random-mylist (values-from random-sample-set [arena-grammar-state]) ;from the set of network speakers, the higher the no. of connections, the more they speakforeach network-sample-set   [  repeat (length neighbor-nodes-of self)  ;how many nodes connections do I have? repeat that no. of times    [set sample-set2 lput arena-grammar-state sample-set2 ]  ]set mylist  sentence sample-set2 random-mylist   ;Using the grammar state values, set "mylist2" to comprise utterances of either 1 or 0  foreach mylist     [    ifelse (random-float 1 <= ? )       [set mylist2 lput 1 mylist2 ]      [set mylist2 lput 0 mylist2 ]    ]     ; make a copy of "mylist2" so that it can be multiplied by the number of "utterances" from each speaker  set mylist-temp mylist2       ;"mylist2" is then expanded depending on how many "utterances" are sampled from each speaker    repeat (utterances - 1)    [     set mylist2 sentence mylist-temp mylist2   ]      ;make the lists that go into the algorithm a consistent length  set mylist2 random-n-of ((round((proportion-to-sample) * num-patches)) * utterances )  mylist2    ;randomize the list set mylist2 (shuffle mylist2)  set utt/acq (length mylist2) ;for keeping track of total # utterances per acquisition cycle     ;introduce the bias here  set perceived-grammar-state ((length (filter [ ? = 1] mylist2) ) /                             ((length (filter [ ? = 1] mylist2) ) + ((1 - alpha) * (length (filter [ ? = 0] mylist2)))))      foreach  mylist2        [         ifelse (random-float 1 <= perceived-grammar-state )         [            set acquirer-grammar-state (acquirer-grammar-state + (gamma * ( 1 - acquirer-grammar-state)))         ]         [           set acquirer-grammar-state ((1 - gamma ) * acquirer-grammar-state )         ]       ]end  to speakask nodes      [      set arena-grammar-state-of patch-here ( acquirer-grammar-state )      ]endto update-colors ask nodes   [    set color scale-color red acquirer-grammar-state 0 1   ]  ask patches   [    set pcolor scale-color black arena-grammar-state 0 1   ]  if (hide-edges? = true)     [    ask edges     [       ifelse  (any? edges with [color = gray])          [hideturtle]         [showturtle]     ]   ]endto do-plots  set-current-plot "grammar states"  set-current-plot-pen "arena"  plot (mean values-from patches [arena-grammar-state])  set-current-plot-pen "individual"   plot (value-from (turtle 0) [acquirer-grammar-state])  set arena-mean (mean values-from patches [arena-grammar-state])end@#$#@#$#@GRAPHICS-WINDOW26510639405121214.561101110001CC-WINDOW5539648634Command Center0BUTTON62597102NILsetupNIL1TOBSERVERTNILBUTTON1602724460NILgoT1TOBSERVERNILNILMONITOR1142179470# of nodescount nodes31BUTTON162333249417resize nodesresize-nodesNIL1TOBSERVERTNILSLIDER265415554448proportion-to-sampleproportion-to-sample010.10.011NILSLIDER265451556484utterancesutterances01001011NILSLIDER266

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -