Random Walks

In many situations, it is very useful to think of some sort of process that you wish to model as a succession of random steps. This can describe a wide variety of phenomena - the behavior of the stock market, models of population dynamics in ecosystems, the properties of polymers, the movement of molecules in liquids or gases, modeling neurons in the brain, or in building Google's PageRank search model. This type of modeling is known as a "random walk", and while the process being modeled can vary tremendously, the underlying process is simple. In this exercise, we are going to model such a random walk and learn about some of its behaviors!

Learning goals:

  • Model a random walk
  • Learn about the behavior of random walks in one and two dimensions
  • Plot both the distribution of random walks and the outcome of a single random walk

Group members

Put the name of your group members here!

Part 1: One-dimensional random walk.

Imagine that you draw a line on the floor, with a mark every foot. You start at the middle of the line (the point you have decided is the "origin"). You then flip a "fair" coin N times ("fair" means that it has equal chances of coming up heads and tails). Every time the coin comes up heads, you take one step to the right. Every time it comes up tails, you take a step to the left.

Questions:

  • After $N_{flip}$ coin flips and steps, how far are you from the origin?
  • If you repeat this experiment $N_{trial}$ times, what will the distribution of distances from the origin be, and what is the mean distance that you go from the origin? (Note: "distance" means the absolute value of distance from the origin!)

First: as a group, come up with a solution to this problem on your whiteboard. Use a flow chart, pseudo-code, diagrams, or anything else that you need to get started. Check with an instructor before you continue!

Then: In pairs, write a code in the space provided below to answer these questions!


In [ ]:
# put your code for Part 1 here.  Add extra cells as necessary!

Part 2: Two-dimensional walk

Now, we're going to do the same thing, but in two dimensions, x and y. This time, you will start at the origin, pick a random direction, and take a step one foot in that direction. You will then randomly pick a new direction, take a step, and so on, for a total of $N_{step}$ steps.

Questions:

  • After $N_{step}$ random steps, how far are you from the origin?
  • If you repeat this experiment $N_{trial}$ times, what will the distribution of distances from the origin be, and what is the mean distance that you go from the origin? (Note: "distance" means the absolute value of distance from the origin!) Does the mean value differ from Part 1?
  • For one trial, plot out the steps taken in the x-y plane. Does it look random?

First: As before, come up with a solution to this problem on your whiteboard as a group. Check with an instructor before you continue!

Then: In pairs, write a code in the space provided below to answer these questions!


In [ ]:
# put your code for Part 2 here.  Add extra cells as necessary!

Part 3: A different kind of random walk.

If you have time, copy and paste your 1D random walk code in the cell below. This time, modify your code so that the coin toss is biased - that you are more likely to take a step in one direction than in the other (i.e., the probability of stepping to the right is $p_{step}$, of stepping to the left is $1-p_{step}$, and $p_{step} \neq 0.5$).

How does the distibution of distances gone, as well as the mean distance from the origin, change as $p_{step}$ varies from 0.5?


In [ ]:
# put your code for Part 3 here.  Add extra cells as necessary!

Wrapup

Question: Do you have any lingering questions that remain after this project?

Put your answers here!

Turn it in!

Whether you've completed it or not, turn this assignment in to the Day 9 dropbox in the "in-class activities" folder."