2
votes

I am first time poster, six month reader. I love this site and am grateful for the vast array of topics covered. Now that I am feeling a bit more competent using NetLogo, I've tried some harder stuff and got stuck...

Basically, I have created a membership function which measures agents against one another on a vector containing two variables (opinions on rock and hip-hop):

to-report membership [ agent1 agent2 ]
let w 0.5
let w2 sq w
report exp (- d2 agent1 agent2 / w2)
end

where

;;;;;;;;;;;;;;Shortcut functions;;;;;;;;;;;;;;;;;;;;;;;;;;;

to-report d2 [agent1 agent2 ]
  report ( (sq ([rock] of agent1 - [rock] of agent2)) + (sq ([hip-hop] of agent1 - [hip-hop] of agent2)) )
end

to-report sq [ x ]
  report x * x
end

This all works fine, and I am able to compare any two agents without problem. However, my trouble arises when I try to compare a single agent [agent1] with all of the agents within his neighbourhood.

to go
    ask turtles [
    let neighbours turtle-set turtles in-radius neighbourhood
    show membership self neighbours] 
end

Whenever I run this model I receive an error that the d2 reporter expected an input not a list - which I theoretically understand - by having a neighbourhood of 1+ agent(s), the calculation is receiving for example [0.1 0.8] [0.2 0.4] [0.5 0.6]..............

I was just wondering, is there any way that the procedure can consider all of the neighbours and arrive at one single membership number? I have searched extensively through posts and a couple of netlogo books I have, but no luck so far. Thank you for taking the time to read this post and for any helpful comments.

1

1 Answers

1
votes

Your understanding of what is happening is correct: your membership reporter expects two individual agents and you are passing it an agent and an agentset. To calculate each membership individually, and get back a list of membership values, you can use of:

to go
  ask turtles [
    let neighbours turtle-set turtles in-radius 10
    show [ membership myself self ] of neighbours
  ]
end

Notice the use of myself and self, which can sometimes be tricky to understand. In this case, self is the neighbour and myself is the outer asking turtle.

So now you have a list of membership numbers, but you wonder:

is there any way that the procedure can consider all of the neighbours and arrive at one single membership number?

There are plenty of ways! But we can't really tell you which one to use: it depends on your model and what you want to do with it.

If you wanted something very straightforward, you could just take the mean of the list:

show mean [ membership myself self ] of neighbours

...but I don't know if it makes sense in your context. In any case, NetLogo has plenty of mathematical primitives that you should be able to use to arrive at the number you want.