Multiple Movement Probabilities Please Help!

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Multiple Movement Probabilities Please Help!

shayla19
Hi I am trying to write a code to simulate a dorm buildings behavior and I am trying to model the movements of students within by creating multiple probabilities of which room they will move/ stay in for different times of the day. I have tried multiple methods using if and ifelse statments but the "decisions" the turtles to go to each room build off of the previous command when I want it to decide between 5 types of rooms at the same time. Here is one attempt I had:

 if ticks <= 400
  [ask turtles
    [ifelse random-float 1 < dr-stay-before-400
    [setxy -4 random-ycor]
      [if (random-float 1 <= dr-leave-before-400)
      [setxy -8 random-ycor]
      if (random-float 1 > dr-leave-before-400) and (random-float 1 <= dr-br-before-400)
      [setxy 0 random-ycor]
      if (random-float 1 > dr-br-before-400) and (random-float 1 <= dr-cr-before-400)
      [setxy 4 random-ycor]
      if (random-float 1 > dr-cr-before-400) and (random-float 1 <= dr-lr-before-400)
      [setxy 8 random-ycor]
              ]]]
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Movement Probabilities Please Help!

shayla19
Update:
Im not sure if this is a viable method but..

 if ticks <= 400
      [ask n-of ((count turtles with [pcolor = orange]) * (1 - dr-stay-before-400)) turtles [setxy -4 random-ycor]
          ask n-of ((count turtles with [pcolor = orange]) * (dr-leave-before-400)) turtles [setxy -8 random-ycor]
          ask n-of ((count turtles with [pcolor = orange]) * (dr-br-before-400)) turtles [setxy 0 random-ycor]
          ask n-of ((count turtles with [pcolor = orange]) * (dr-cr-before-400)) turtles [setxy 4 random-ycor]
          ask n-of ((count turtles with [pcolor = orange]) * (dr-lr-before-400)) turtles [setxy 8 random-ycor]
       ask n-of ((count turtles with [pcolor = red]) * (1 - dr-leave-before-400)) turtles [setxy -8 random-ycor]
          ask n-of ((count turtles with [pcolor = red]) * (dr-stay-before-400)) turtles [setxy -4 random-ycor]
          ask n-of ((count turtles with [pcolor = red]) * (dr-br-before-400)) turtles [setxy 0 random-ycor]
          ask n-of ((count turtles with [pcolor = red]) * (dr-cr-before-400)) turtles [setxy 4 random-ycor]
          ask n-of ((count turtles with [pcolor = red]) * (dr-lr-before-400)) turtles [setxy 8 random-ycor]
       ask n-of ((count turtles with [pcolor = blue]) * (1 - dr-br-before-400)) turtles [setxy 0 random-ycor]
          ask n-of ((count turtles with [pcolor = blue]) * (dr-leave-before-400)) turtles [setxy -8 random-ycor]
          ask n-of ((count turtles with [pcolor = blue]) * (dr-stay-before-400)) turtles [setxy -4 random-ycor]
          ask n-of ((count turtles with [pcolor = blue]) * (dr-cr-before-400)) turtles [setxy 4 random-ycor]
          ask n-of ((count turtles with [pcolor = blue]) * (dr-lr-before-400)) turtles [setxy 8 random-ycor]
       ask n-of ((count turtles with [pcolor = green]) * (1 - dr-cr-before-400)) turtles [setxy 4 random-ycor]
          ask n-of ((count turtles with [pcolor = green]) * (dr-leave-before-400)) turtles [setxy -8 random-ycor]
          ask n-of ((count turtles with [pcolor = green]) * (dr-stay-before-400)) turtles [setxy -4 random-ycor]
          ask n-of ((count turtles with [pcolor = green]) * (dr-br-before-400)) turtles [setxy 0 random-ycor]
          ask n-of ((count turtles with [pcolor = green]) * (dr-lr-before-400)) turtles [setxy 8 random-ycor]
       ask n-of ((count turtles with [pcolor = white]) * (1 - dr-lr-before-400)) turtles [setxy 8 random-ycor]
          ask n-of ((count turtles with [pcolor = white]) * (dr-leave-before-400)) turtles [setxy -8 random-ycor]
          ask n-of ((count turtles with [pcolor = white]) * (dr-stay-before-400)) turtles [setxy -4 random-ycor]
          ask n-of ((count turtles with [pcolor = white]) * (dr-br-before-400)) turtles [setxy 0 random-ycor]
          ask n-of ((count turtles with [pcolor = white]) * (dr-cr-before-400)) turtles [setxy 4 random-ycor]
    ]
end
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Movement Probabilities Please Help!

NetLogo-Users mailing list
Shayla,

Did you get any replies to your question? Did you like any of them :)

I'm not sure what you want to do. Do you want to ask each turtle during
each tick to choose only one room, go there, then do it again the next
tick, up through tick 400? Do you have different kinds of turtles
represented by colors and each color has a different set of choices?

One thing about your first method is that you were sampling random-float
multiple times. That results in your actual distribution being somewhat
different from the uniform distribution you get from random-float. That
matters in that you may be skewing the outcome in ways you weren't
anticipating.

The thing about your second method (below)  is that, while you're
computing the probability of a move based on the number of turtles of a
certain color, you're not picking turtles of that color. Your moving n
turtles out of the total number of turtles. Furthermore, you're sampling
n turtles with replacements, meaning that you will move some turtles
multiple times, and some turtles not at all.

At any rate, there are simpler ways to do what you want to do, but I
would need to understand your problem a bit better to recommend something.

-dave

On 07/12/2017 02:50 PM, shayla19 [hidden email]
[netlogo-users] wrote:

>
> Update:
> Im not sure if this is a viable method but..
>
> if ticks <= 400
> [ask n-of ((count turtles with [pcolor = orange]) * (1 -
> dr-stay-before-400)) turtles [setxy -4 random-ycor]
> ask n-of ((count turtles with [pcolor = orange]) *
> (dr-leave-before-400)) turtles [setxy -8 random-ycor]
> ask n-of ((count turtles with [pcolor = orange]) *
> (dr-br-before-400)) turtles [setxy 0 random-ycor]
> ask n-of ((count turtles with [pcolor = orange]) *
> (dr-cr-before-400)) turtles [setxy 4 random-ycor]
> ask n-of ((count turtles with [pcolor = orange]) *
> (dr-lr-before-400)) turtles [setxy 8 random-ycor]
> ask n-of ((count turtles with [pcolor = red]) * (1 -
> dr-leave-before-400)) turtles [setxy -8 random-ycor]
> ask n-of ((count turtles with [pcolor = red]) *
> (dr-stay-before-400)) turtles [setxy -4 random-ycor]
> ask n-of ((count turtles with [pcolor = red]) *
> (dr-br-before-400)) turtles [setxy 0 random-ycor]
> ask n-of ((count turtles with [pcolor = red]) *
> (dr-cr-before-400)) turtles [setxy 4 random-ycor]
> ask n-of ((count turtles with [pcolor = red]) *
> (dr-lr-before-400)) turtles [setxy 8 random-ycor]
> ask n-of ((count turtles with [pcolor = blue]) * (1 -
> dr-br-before-400)) turtles [setxy 0 random-ycor]
> ask n-of ((count turtles with [pcolor = blue]) *
> (dr-leave-before-400)) turtles [setxy -8 random-ycor]
> ask n-of ((count turtles with [pcolor = blue]) *
> (dr-stay-before-400)) turtles [setxy -4 random-ycor]
> ask n-of ((count turtles with [pcolor = blue]) *
> (dr-cr-before-400)) turtles [setxy 4 random-ycor]
> ask n-of ((count turtles with [pcolor = blue]) *
> (dr-lr-before-400)) turtles [setxy 8 random-ycor]
> ask n-of ((count turtles with [pcolor = green]) * (1 -
> dr-cr-before-400)) turtles [setxy 4 random-ycor]
> ask n-of ((count turtles with [pcolor = green]) *
> (dr-leave-before-400)) turtles [setxy -8 random-ycor]
> ask n-of ((count turtles with [pcolor = green]) *
> (dr-stay-before-400)) turtles [setxy -4 random-ycor]
> ask n-of ((count turtles with [pcolor = green]) *
> (dr-br-before-400)) turtles [setxy 0 random-ycor]
> ask n-of ((count turtles with [pcolor = green]) *
> (dr-lr-before-400)) turtles [setxy 8 random-ycor]
> ask n-of ((count turtles with [pcolor = white]) * (1 -
> dr-lr-before-400)) turtles [setxy 8 random-ycor]
> ask n-of ((count turtles with [pcolor = white]) *
> (dr-leave-before-400)) turtles [setxy -8 random-ycor]
> ask n-of ((count turtles with [pcolor = white]) *
> (dr-stay-before-400)) turtles [setxy -4 random-ycor]
> ask n-of ((count turtles with [pcolor = white]) *
> (dr-br-before-400)) turtles [setxy 0 random-ycor]
> ask n-of ((count turtles with [pcolor = white]) *
> (dr-cr-before-400)) turtles [setxy 4 random-ycor]
> ]
> end
>
> --
> View this message in context:
> http://netlogo-users.18673.x6.nabble.com/Multiple-Movement-Probabilities-Please-Help-tp5006541p5006542.html
> Sent from the NetLogo-Users mailing list archive at Nabble.com.
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Multiple Movement Probabilities Please Help!

shayla19
Hi dave,
Thanks for your inquiry.
The turtles themselves do not have their own colors. There are different color patches for each of the xcor and I want the turtles to move to these different colored patches or stay on their color patch based on a probability for each.
Reply | Threaded
Open this post in threaded view
|

Re: Multiple Movement Probabilities Please Help!

NetLogo-Users mailing list
Shayla,

Okay, I think I get it now.

Let's say the probability of changing rooms is dr-leave-before-400 (and
the probability of staying is 1 - dr-leave-before-400). Furthermore,
let's say that the probability of going to a specific room is the same
for all rooms (that is, for five rooms, the probability of going to any
one of them is 0.2). This can be done with

   ask turtles [
     if random-float 1 < dr-leave-before-400 [
       let room-xcor 4 * ((random 5) - 2
       setxy room-xcor random-ycor ]
   ]

If the probability of going to a room is different for each room, it
gets a bit more complicated.

-dave


On 07/18/2017 02:16 PM, shayla19 [hidden email]
[netlogo-users] wrote:

>
> Hi dave,
> Thanks for your inquiry.
> The turtles themselves do not have their own colors. There are different
> color patches for each of the xcor and I want the turtles to move to these
> different colored patches or stay on their color patch based on a
> probability for each.
>
> --
> View this message in context:
> http://netlogo-users.18673.x6.nabble.com/Multiple-Movement-Probabilities-Please-Help-tp5006541p5006547.html
> Sent from the NetLogo-Users mailing list archive at Nabble.com.
>
>