Question: Please help me with my project 7 CS 1400 Project 7: Random Walk Problem Expected Duration: 4 hours Prerequisites: None. In 1827, the Scottish botanist

Please help me with my project 7 CS 1400

Project 7: Random Walk

Problem

Expected Duration: 4 hours

Prerequisites: None. In 1827, the Scottish botanist Robert Brown observed that pollen particles suspended in water seemed to float around at random. He had no plausible explanation for what came to be known as Brownian motion, and made no attempt to model it mathematically. Louis Bachelier presented a clear mathematical model in his doctoral thesis, The Theory of Speculation in 1900. His thesis was largely ignored by respectable academics because it dealt with the then disreputable field of understanding financial markets. In 1905, Albert Einstein used similar stochastic thinking in physics to describe how it could be used to confirm the existence of atoms. People seemed to think that understanding physics was more important than making money, and the world started paying attention.

Brownian motion is an example of a random walk. Today, random walks are widely used to model physical processes like diffusion, biological processes like the kinetics of displacement of RNA from heteroduplexes by DNA, and social processes like movements of the stock market.

We are interested in random walks because of their wide applications to many problems, and for learning more about how to structure simulations nicely in Python.

Farmer John has an old grandparent (Pa) that likes to wander off randomly when working in the barn. Pa starts from the barn and every second take one step in a random direction North, South, East or West. What is Pas expected distance away from the barn after 1000 steps? If Pa takes many steps, will Pa be likely to move ever further from the origin, or be more likely to wander back to the origin over and over, and end up not far from where she started? Lets write a simulation to find out.

This particular barn is in the center of a large grassy field. One day Pa starts to wander off, and notices that the grass has been mysteriously cut (by John) to resemble graph paper. Notice that after one step Pa is always exactly one unit away from the start. Lets assume that Pa wanders eastward from the initial location on the first step. How far away might Pa be from the initial location after the second step? John sees that with a probability of 0.25 Pa will be 0 units away, with a probability of 0.25 Pa will be 2 units away, and with a probability of 0.5 Pa will be 2 units away. So, on average Pa will be further away after two steps than after one step. What about the third step? If the second step is to the north or south, the third step will bring the farmer closer to origin half the time and further half the time. If the second step is to the west (back to the start), the third step will be away from the origin. If the second step is to the east, the third step will be closer to the origin a quarter of the time, and further away three quarters of the time.

It seems like the more steps Pa takes, the greater the expected distance from the origin. We could continue this exhaustive enumeration of possibilities and perhaps develop a pretty good intuition about how this distance grows with respect to the number of steps. However, it is getting pretty tedious, so it seems like a better idea to write a program to do it for us.

However, there are a couple more twists to the situation. Pas wife Mi-Ma, another grandparent of Johns, also likes to wander away randomly, but riding an old mule. The mule goes South twice as often as any other direction. Lastly, Johns favorite hog Reg has an odd habit of wandering off too, but only randomly going east or west at each step, never north or south. People think hes a sun-follower, but nobodys really sure. John figures your Python program ought to model these two as well, while youre at it.

Part 1 of your program should take three parameters as input: 1) a list of walk lengths to simulate, 2) the number of trials, or times to try each walk length, and 3) which type of walk we are modelingPa, Mi-Ma or Reg. Assume the wanderer always starts at 0,0 in an infinite grid. With a seed value of 20190101 for the random number generator, your output values should be close to the examples given below. So much depends on the order in which random numbers are consumed, and exactly how they are used, but the mean distance for final location should be pretty close no matter how movement is modeled. The format of the output should be the same.

Pa random walk of 100 steps Mean = 8.5 CV = 4.7 Max = 19.8 Min = 1.4 Pa random walk of 1000 steps Mean = 31.4 CV = 14.3 Max = 57.0 Min = 1.4 Mi-Ma random walk of 100 steps Mean = 26.7 CV = 10.8 Max = 52.6 Min = 7.6 Mi-Ma random walk of 1000 steps Mean = 243.4 CV = 37.1 Max = 318.2 Min = 156.2 Reg random walk of 100 steps Mean = 7.6 CV = 6.0 Max = 22.0 Min = 0.0 Reg random walk of 1000 steps Mean = 33.2 CV = 23.9 Max = 86.0 Min = 0.0

In the output above:

  • mean is the average distance over all walks of that length as the crow flies
  • max is the longest distance as the crow flies
  • min is the shortest distance as the crow flies
  • CV is the variance

Part 2 of your program should plot a sample of final locations in a turtle window, in order to visualize their behaviors. Your output should be similar to the picture below. For plotting, do only one plot: plot all three characters for 50 trials on walk length 100. Dont plot the 1000 walk length. Too much pain for no gain. Hint: The fastest programs calculate all final locations first, separate from plotting, and only move turtles to plot final locations.

Submission

Your source file should be called main.py. Your screenshot should be called random_walk.png. Submit both files in zip file random_walk.zip.

Grading

Late submissions receive 50 points and no feedback.

0-20 points: design doc is correct and complete 21-100: all automated and manual tests pass

Test Cases

  1. Pa for 100 steps for 50 trials
  2. Pa for 1000 steps for 50 trials
  3. Mi-Ma for 100 steps for 50 trials
  4. Mi-Ma for 1000 steps for 50 trials
  5. Reg for 100 steps for 50 trials
  6. Reg for 1000 steps for 50 trials
  7. each case above works gives the same output on two or more runs when the same seed is used
  8. Code works with a few random test cases we dont tell you about.
  9. Code uses lists, tuples or dictionaries as appropriate to organize data
  10. Code uses parameterized functions to organize and generalize the code
  11. Graph final locations for Pa, Mi-Ma and Reg (3 test cases) as shown
  12. code quality test passes with 0 errors

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!