Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Pa starts from barn and every second takes one step. One day Pa starts to wander off, and notices that the grass has been mysteriously

Pa starts from barn and every second takes one step. One day Pa starts to wander off, and notices that the grass has been mysteriously cut 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 probability of 0.5 Pa will be 2 units away. On average Pa will be further away after two steps than after one step. If the second step is to the north or south, the third step will bring the farmer closer to origin half the time, further half the time. The third step will be away from the origin. If the second step is to the east the third step will be closer to origin a quarter of time, and further away three quarters of 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. Pas wife Mi-Ma, another grandparent of Johns, also likes to wander away randomly, but riding a mule. The mule goes South twice as often as any other direction. Lastly, Johns hog Reg has an odd habit of wandering off too, but only randomly going east or west at each step, never north or south. Your Python program ought to model these two as well. Info on intructions:
simulate()
Define a function called simulate() that takes three parameters:
A list of walk lengths to simulate,
The number of trials (how many times to do walks of the specified lengths), and
Which walker we are modeling: 'Pa,'Mi-Ma, 'Reg, or 'all.
For your convenience, define a main() function (that runs with conditional execution, per usual). main() should read the following three arguments from the command line:
A list of comma-separated walk lengths to simulate (there should be no spaces in this list),
the number of trials, or times to try each walk length, and
which type of walk we are modeling: 'Pa,Mi-Ma or Reg or 'all.
If invoked with python3 random_walk.py 100,100050 all, your main() function should call simulate([100,1000],50, 'all').
Assume the wanderer always starts each walk at (0,0) in an infinite grid. On individual tests, your output values should be close to the examples given below, though they wont be exactly the same. The format of the output should be the same.
Pa random walk of 100 steps
Mean =8.5 CV =0.6
Max =19.8 Min =1.4
Pa random walk of 1000 steps
Mean =31.4 CV =0.5
Max =57.0 Min =1.4
Mi-Ma random walk of 100 steps
Mean =26.7 CV =0.4
Max =52.6 Min =7.6
Mi-Ma random walk of 1000 steps
Mean =243.4 CV =0.2
Max =318.2 Min =156.2
Reg random walk of 100 steps
Mean =7.6 CV =0.8
Max =22.0 Min =0.0
Reg random walk of 1000 steps
Mean =33.2 CV =0.7
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, and
CV is the Coefficient of Variance, defined as the standard deviation divided by the mean.
Round all values to one decimal point, as shown.
All distances should be in steps.
plot()
Define a function called plot() that plots a sample of final locations in a turtle window in order to visualize their behaviors. plot() should expect no arguments. Your output should be similar to the picture below. Do only one plot: plot all three characters for 50 trials on walk length 100. Dont plot the 1000 walk length; it takes too long.
.guides/img/random_walk
Details of plot()
In order to ensure that your output matches expected output, do the following:
Use turtle.shape()(docs) to change the turtles shape (the three shapes are 'circle, 'square, and triangle).
Use turtle.color()(docs) to change the turtles color ('black, 'green, and red).
Use turtle.stamp()(docs) to plot individual points.
Use turtle.shapesize()(docs) to scale the shapes to half of their original size in both dimensions.
Use turtle.speed()(docs) and set it to the fastest speed if you have trouble with timing out.
Use a scale of five pixels (for the turtle) per step (for Pa, Mi-Ma, or Reg).
Set the size of the screen to 300x400.
When you are finished, call the provided save_to_image() function
I have some code done. But I'm not sure what I need to change about it. The rubric, expected/needed output, and my code so far is in the picture.
I would like a detailed walkthrough and answer in python. I am thoroughly confused.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

Contact person at the organization

Answered: 1 week ago

Question

Brief the importance of span of control and its concepts.

Answered: 1 week ago

Question

What is meant by decentralisation?

Answered: 1 week ago

Question

What are the steps in the T&D process?

Answered: 1 week ago

Question

Define training and development.

Answered: 1 week ago