Wiggle Walk

Hi, this is Joel Castellanos of the University of New Mexico with the CS4All video on the wiggle walk, which is an extension of the random walk from the last video and the use of sliders to control global variables in net logo. [Slide 1] This is a net logo simulation of the motion of a relatively heavy particle being bombarded by many much lighter particles.

In this model, all of the collisions are perfectly elastic. That means that when particles collide, there is no energy lost from heat or for deformation of the particles or any thing else. When particles collide, some of the energy might transfer from one particle to another, but the total amount of kinetic energy is the same before the collision and after the collision.

It is important to point out that this is not a model of Brownian motion. Brownian motion is the motion of particles suspended in a liquid or gas resulting from their bombardment by fast moving atoms or molecules. This elastic collision model is fundamentally different from Brownian motion.

First, Brownian motion describes a phenomenon that occurs in three dimensions of motion. The motion in this model is in only two dimensions. This difference should not be trivialized by saying, "Well, it's the same thing just with an extra dimension. The transition from two dimensions to three dimensions does not just make the calculations more complicated. It fundamentally changes the statistical nature of the objects.

Second, the white circle in this model is receiving an average of about 11 collisions per second. By contrast, a particle of fat suspended in a glass of homogenized milk experiences [on the order 00:01:34] of 100 quintillion collisions per second. This model of a heavy white circle undergoing about 11 elastic collisions per second can help us visualize and understand Brownian motion, but it is not a model of Brownian motion and it's statistical properties are fundamentally different.

Enough of the aside, the reason we are looking at this model is that it provides an example of a path that appears to be composed of many random turns, yet is much straighter than the path produced by the random walk we developed in the last video.

In this video, we'll be developing a modification to the random walk, which we'll call the wiggle walk. The wiggle walk, as we will implement it, results in the path having a shape, similar to that of the heavy white circle in this model. I emphasize the word shape because the motion of the heavy white circle is changing in both direction and in speed. By contrast, the wiggle walk will change direction, but will always move the same distance in each time step.

In the last video, I claimed that the random walk was commonly used by models that needed to approximate the search path of ants and bees. Larger animals, such as deer foraging for food in the forest, tend to follow a much straighter path than that produced by the random walk. The path of a deer foraging for food would be better approximated by the wiggle walk.

A more accurate model of a foraging deer would involve it's [apology 00:02:49] of the land, including cliffs, boulders, trees, undergrowth, thickets, clearings, trails, and streams. It would include behaviors of the deer that make it more or less likely to move towards or away from these features. It would include specific locations of specific types and quantities of food and the ability of the deer to sense that food by sight or smell from some distance.

The wiggle walk can serve as a first approximation to motion that would emerge in a more complex model. The wiggle walk is especially useful in the early development stages of a model before data collection is complete or when the actual forces affecting the motion are not well understood.

As mentioned before, the white circle represents a particle with a relatively large mass. Therefore, it's motion has a relatively large amount of momentum. It's momentum is a measure of it's resistance to change. Collision with a small green particle can only perturb it's motion by a small amount. Many collisions with the little green particles, as you can see, can completely reverse it's direction.

Generally, the wiggle walk will be a good first approximation for many systems that have momentum and a particular direction and are being perturbed by some outside force. Whether this is a physical system, such as this heavy white particle moving through a bombardment of a much lighter particles or a metaphorical momentum, such as modeling the policy decisions of a senator who's been in office for many years.

This simulation you're watching right now is using a lot of computational power. There are 2,000 particles, each one checking for collisions and updating it's position 30 times a second. The wiggle walk is computationally very simple. [Slide 2] I have started up net logo and opened up the random walk model that we were working on in our last video. Instead of changing the code in random walk, we're going to keep that random walk and make another button.

We're going to go to "Button" and this button's going to call the wiggle walk. We also want this one to go forever. The new button is showing the red error state because we don't yet have a procedure called wiggle walk. Go up to the code tab. Here's our code for random walk, our wiggle walk is going to be similar to that, so copy the random walk, paste it down here, change random to wiggle. We're still going to ask turtles. We're going to change direction, move forward 1, and then after we're done with looping thought the turtles, advance [the 00:05:00] tick counter.

This is the part that changes. Instead of setting heading, we're going to turn right by a random angle between 0 and 90 degrees. Then, we're also going to turn left by a random number between 0 and 90 degrees. With the random walk all of the possible outcomes that we could set our heading to [are 00:05:24] each equally likely.

With the wiggle walk, some outcomes are much more likely than others. For example, the only way we could turn to the right by 90 degrees is if the right random number is 90 and the left random number is 0, but there are two ways that we could turn to the right by 89 degrees. If the right turn is chosen at 90 and the left is chosen at 1, then we would end up going to the right by 89 or if the right is 89 and the left is 0, we would got the right at 89. There's two different ways ... It's twice as likely to turn to the right by 89 than it is to turn the right by 90.

As we pick smaller and smaller angles, there's more and more different ways to get that same outcome. In fact, there's 90 different ways that we could go directly straight. If turn right is 0 and turn left is 0, we continue straight. If turn right is 1 and left is 1, right is 2 and left is 2, etcetera, there's 90 different ways that we can get the same outcome of moving straight ahead.

This makes what's called a triangular distribution, where as this is called the uniform distribution. Every possibility is equally likely here. With the wiggle walk, the most likely possibility is to continue straight. Larger and larger angles, either to the right or to the left, are less and less probable.

Let's now run this code. Here on the interface tab, the same set up procedure can be used either for the random walk or the wiggle walk. We'll click the wiggle walk now. Wiggling along. We have implemented our wiggle walk to always choose numbers between 0 and 90 for the two turn angles. We can get very wiggly patterns by using different ranges of numbers for our turn angles. Rather than going into the code and changing those hard coded values, we're going to add a slider that sets a global variable.

To do this, I'll go up the widget drop down and select "Slider," add a slider in here. When I do this. A dialog box comes up for me to configure the slider. First I have to give a name that will appear in the slider and will also be the global variable that can be used in the code section. I'm going to call this max angle because we're going to use it as the maximum angle that we can turn by.

We'll pass this as an argument into the random reporter and I'm going to set the minimum value for 0 so we'll just always be going straight ahead and the maximum value to 180 so we could turn at the most 180 to the left or 180 to the right, which would give us the full range of motion. Then, for our initial default value, I'll leave this as 50. Then, click "Okay."

Now we have a slider. It's current value is 50. The value of this slider is going to affect the global variable called max angle. As I slide this slider now, I can change it's value. Right now, it has no effect on the program, though. It's just a slider that's not used anywhere.

Now, I go to the code section and we'll make use of our new variable. The random walk procedure won't make use of our new variable, but the wiggle walk will. Where I'm choosing right now, random and the hard coded value 91, we'll change this to max angle. This needs to be spelled exactly the same way that we spelled it on the slider. Random max angle will choose a number between 0 and up to but not including this angle. I want to add 1 to it. We'll go from 0 to 180 and balance those parenthesis.

What this does is takes the current value of the slider, wherever this slider is set, adds 1 to that value, and then we're going to pass that number as an argument into the random reporter. The random reporter goes into turning right. We're going to do that same thing for turning left.

That's all the changes. Now, we're using that angle. We can go back to our interface and see the effect that it has. Up 2 interface. I'll speed up the slider, set up, and change the max angle now down to 10 and start the wiggle walk.

You can see the path is, of course, much straighter. If I bring this up to a much larger number, 110, hit "Set up" again, come down and click "Wigglewalk" and now on average, it's making much larger turns than it did when the max angle was set to 10.

Now, I'm going to load another model that will let us take a closer look at the properties of these two walks. This model has seven turtles, each of which is doing the wiggle walk. In this model, the maximum turn angle to the left and the maximum turn angle to the right can be controlled independently.

The wiggle's left slider setting of 5 means that the left turn part of the total turn will be a random integer between 0 and 5. The left and right turn are random variables where each outcome is equally probable. Each turn, each turtle, makes a combined turn, or net turn, that's the result end of it's left turn and it's right turn.

The histogram plot shows a counting of all of these net turns of all of the turtles over all of the time steps. The first column shows the total number of combined, or net, 5 degree turns to the left that can only happen when a turtle makes a 5 degree turn to the left and a 0 degree turn to the right.

The second column shows the total number of 4 degree net, or combined, turns to the left. This outcome can happen in two different ways. Left 4, right 0 or left 5, right 1. There are three ways to get a net, or combined, 3 degree turn to the left.

The overall effect of this is that the net turn angle has a triangular probability distribution. This simple method of combining two uniformly distributed random variables by addition or subtraction to form a single random variable with a triangular distribution is useful in many models other than the wiggle walk.

For example, in a model where agents are [being infected 00:11:05] by some virus, the period of time from when the agent is first infected to when the agent begins showing symptoms is called the incubation period of the virus. The length of this period varies with different individuals and has a normal distribution, or bell curve.

For the requirements of many models, the triangular distribution that we've produced here does a good enough job at modeling a bell curve.

Now, we'll take a look at the histogram of the triangles in the random walk. Set up and in the random walk, each of the 360 different possible values for heading all have equal probability. The jaggedness along the top of the histogram shows that even though all 360 outcomes are equally likely, they're not all occurring the same number of times. It's precisely this jaggedness that keeps the random walk from staying in a small area.

That's it for tonight. Thanks for watching.

WiggleWalk / Page 1 of 5