Complex Systems Summer School 2000

Multiple Random Walks  with StarLogo

During Ronnie Mainieri's discussions on random walks, he mentioned that, even though the average distance away from the origin was 0, this was due to being able to be on either side of the origin.  In fact, he said, if you disregard that and consider only absolute distance from the origin, the random walker drifts away from the origin proportional to the square root of the "time" or "steps".

This seemed  a bit hard to believe, but after looking up random walks in Cosma Shalizi's math review notes (page 47) it appears that this is indeed true.

Well, it seemed to me that StarLogo was a good way to visualize this so I decided on a simulation that would let me "see" this behavior.

The Simulation: Turtles all the way down!

It took a bit to figure out how to see more than one walk at a time.  To do so, I arranged for the turtles to be stacked one above each other, and constrained to move only in the X direction.

To make the evolution of the walk clear, I painted the path taken by the turtle yellow, but kept the turtle itself red.  This was done by using both the patch color (yellow) and the turtle color (red).

Here is the initial setup .. the Y axis all red due to a red turtle being on each Y coordinate.  I then let the simulation run a few steps to show the overall strategy: lots of turtles (101 of them .. equal to the screen-height) with yellow paths showing earlier motion and a red dot at the current X coordinate.  Note that the turtle currently not being at the end of its maximum previous travel is obvious: a yellow space between the red dot for the turtle and the black where it has not yet reached.

Click images for larger size

The gauges and buttons on the left are start/stop buttons, and displays of interesting variables.  Variables shown are the distance for the "max" turtle, the distance for the "min" turtle (generally 0 or 1, depending if steps are even or odd), the X average (always near 0), the average distance for all the turtles (absolute value of X), and the current number of steps taken by the turtles.

Here is the result after 200 steps:

The Plot Thickens

This was all well and good, and let me see the evolution of the various walks.  The displays also let me see roughly how the various variables progressed.

But for a more "analytic" feedback, I decided to also use the StarLogo plot function to show the variation of average distance from the origin against the number of steps taken to see if it appeared roughly like a square root function.

Here is the plot for the above 200 step simulation:

And here are three more, shown for 747, 1,000 and 1,503 steps.  Note the roughly square root shape.
 

Click for larger images

Here is the source code.