listnetlogosimilarity

How to create a list of comparisons with an agentset?


The agents (called farms) in my model have peers (an agentset of farms they have links to). Each farm has an attribute called rotation, which is a list of values between 0 and 1 (same length for all farms). I want to create an attribute for each farm that consists of a list of similarity scores (based on Euclidean distance) between the given farms and all its peers, based on their rotations.

Accordingly,

farms-own [
 peers
 rotation
 similarity
]

Rotation is filled from an external dataset. Now, the code I currently have to define similarity is the following:

ask farms [
 let x []
 ask [peers] of myself [
  let y (map * [rotation] of self [rotation] of myself)
  set x lput ((reduce + y) ^ 0.5) x
 ]
 set similarity x
]

Note: The x variable is a way of circumventing the fact that peers cannot set attributes for farms.

This code doesn't work so far. For each farm, similarity should have the same length as the number of peers, which it doesn't (in fact, its length changes between ticks, even though peers are defined in the setup stage and not changed afterwards). Any idea what is wrong here?

Also, if anyone has hints as to how to solve the problem that ask is randomized, so the similarity scores cannot be assigned to concrete peers based on their order (to be used for later operations), they're welcome. But I have some ideas on that, so the above problem has priority.


Solution

  • In case your procedure is called by the observer, the ask [peers] of myself is causing the problem. If you want to ask for the peers of the current tree you can simply ask:

    ask turtles [
     let x []
    ; ask [peers] of myself [
      ask peers [
      let y (map * [rotation] of self [rotation] of myself)
      set x lput ((reduce + y) ^ 0.5) x
     ]
     set similarity x
    ]