Search code examples
netlogoagent-based-modeling

NetLogo, mapping an array of multidimensional variables


I need to estimate the mean value in a network for each dimension of a 3-dimension variable (var_1) . The code I've written doesn't quite do the trick:

    set avg-network map mean ([var_1] of turtles)

What this does is calculating the average for all three dimensions of each turtle instead of the average for each dimension for all turtles. That is:

Turtle0 [0 0 0] Turtle1 [1 1 1] Turtle2 [2 2 2] Turtle3 [3 3 3]

Gives [0 1 2 3]instead of [2 2 2]which is what I am after...


Solution

  • I found a way using the matrix extension. What I do is:

    extensions [ matrix ]
    
    to-report temp-matrix
    let m matrix:from-row-list ([var_1] of turtles)
    report m
    end
    
    to go
      let i 0
      set avg-network n-values 3 [0]
      repeat 3 [
        set avg-network replace-item i avg-network (mean matrix:get-column temp-matrix i)
        set i (i + 1)  
      ]
    end
    

    Not the most elegant but it does the trick. If anyone knows another way I am happy to hear!