Moritz
Moritz

Reputation: 55

NetLogo: comparing neighbors' values

during my model set up on innovation diffusion, another little programming issue occured to me in NetLogo. I would like to model that people more likely learn from people they are alike. Therfore the model considers an ability value that allocated to each agent:

[set ability random 20 ] 

In the go procedure I then want them to compare their own ability value with the values from their linked neighbors. So for example: ability of turtle1 = 5, ability of neighbor1 = 10, ability of neighbor2 = 4. Hence the (absoulute) differences are [ 5, 1]. Hence he will learn more from neighbor2 than from neighbor1.

But I don't know how to approach the problem of asking each single neighbor for the difference. As a first idea, I thought of doing it via a list-variable like [difference1, ..., difference(n)].

So far I only got an aggregated approach using average values, but this is not really consistent with recent social learning theory and might overlay situtations on which the agent has many different neighbors but one who is quite similar to him:

ask turtles
  [
    set ability random 20   
    set ability-of-neighbor (sum [ability] of link-neighbors / count link-neighbors) 
    set neighbor-coefficient (abs (ability - ability-of-neighbor))
;;the smaller the coefficient the more similar are the neighbors and the more the turtle learns from his neighbor(s)

]

Thank you again for your help and advice, and I really appreciate any comments.

Kind regards,

Moritz

Upvotes: 3

Views: 749

Answers (1)

King-Ink
King-Ink

Reputation: 2096

I am having a bit of a time getting my head around what you want but here is a method of ranking link-neighbors.

let link-neighbor-rank sort-on [abs (ability - [ability] of myself)] link-neighbors 

it produces a list of link neighbors in ascending order of difference of ability.

if you only want the closest neighbor use

 let best min-one-of link-neighbors [abs (ability - [ability] of myself)]

I hope this helps.

Upvotes: 3

Related Questions