Reputation: 143
I am creating a supply chain simulation with NetLogo. I am putting a list of lists from NetLogo to R, which is represented by distributor ID (agents who) and sales history (sales of all previous ticks). In R I train my neural network and make predictions. When I put back the answer in the same format list of lists. I need to specify which result goes to which agent. However, I do not know how to do it in NetLogo. I assume that there should be a function to do that, but as I understand the functions are programmed with Java and I would need to assign the values inside the raw code and not in the NetLogo environment. Moreover, I think that this training and predictions occurs multiple times (for each agent) and not only once.
Variable example: [ [0] [ 100 200 300 100 200] ] [ [1] [ 200 300 100 100 200] ]
Where the first index is agents who index and the second is the agent's sales history.
Maybe someone could explain how NetLogo and R can be combined for computational purpose and not only statistical analysis and plotting? I assume that NetLogo is similar to parallel programming, while my style of R programming is more linear.
Upvotes: 0
Views: 142
Reputation: 10336
The last part of your question is beyond me (and may be too broad for typical Stack Overflow questions- I'm not sure you'll get a useful answer here). However, maybe this example would get you in the right direction as to what you're trying to do.
I assume you're using the [r]
extension as in your previous question, so using this setup:
extensions [r]
turtles-own [ rand-num ]
to setup
ca
crt 10 [
set rand-num random 5
]
reset-ticks
end
In this example, turtles have a rand-num
instead of your sales history, but the concept is the same. First, build the list of lists where first index is the turtle [who]
and the second is [rand-num]
, then output it to r (note that I also sort
the list, but that is just for clarity and not actually needed):
to go
let l_list map [ i ->
list i [rand-num] of turtle i
] ( sort [ who ] of turtles )
r:put "list1" l_list
show r:get "list1"
Next, use r:eval
to do whatever you need to do to the values in r- in this example I'm just using lapply
to square the rand-num
value (x[[2]]
)- but make sure to return x
:
let modified_list ( r:get "lapply(list1, function(x) { x[[2]] <- x[[2]]^2; return(x)})" )
Now, to assign the turtles the modified values, use Netlogo's foreach
to iterate over the modified list and ask the turtle of index 0 (turtle item 0 x
) to set its rand-num
to index 1 (set rand-num item 1 x
):
foreach modified_list [ x ->
ask turtle item 0 x [
set rand-num item 1 x
]
]
end
If you check the sort [rand-num] of turtles
before and after running go, you should see the rand-num
of each turtle is squared after go is called.
Upvotes: 1