Lecture 4 Finger Exercise
Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.
Question 1.
Personnel at a certain company are classified as Employees, Managers, or Vice Presidents.
At the end of each workday, an Employee has a Implement in the function below a Monte Carlo simulation that estimates how many days on average it takes a new Employee to become a Vice President.
Include your entire function definition: header and body.
You may assume the For example:prob_em chance of being promoted to Manager.
Similarly, a Manager has a prob_mv chance of being promoted to Vice President after any given day, but also a prob_me chance of demotion back to Employee, where prob_mv + prob_me <= 1.random module is imported for you.def estimate_timeline(prob_em, prob_mv, prob_me, num_trials):
"""
Run a Monte Carlo simulation of num_trials trials to estimate how
many days on average it takes a new Employee to become a Vice
President. The parameters prob_em, prob_mv, and prob_me represent
the promotion and demotion probabilities described above.
"""
estimate_timeline(1, 1, 0, num_trials=100) should evaluate exactly to 2.estimate_timeline(1, 0.5, 0, num_trials=1000) should, with very high probability, evaluate to approximately 3.estimate_timeline(1, 0.5, 0.5, num_trials=1000) should, with very high probability, evaluate to approximately 4.estimate_timeline(0.1, 0.1, 0.1, num_trials=1000) should, with very high probability, evaluate to approximately 30.
Consider a band of thickness 1 centered around the circle's edge, i.e., the region contained between concentric circles with radii r - 0.5 and r + 0.5.
The area of this band has the same numerical value as the circumference.
Throw "darts" within a square that encompasses the outer-most circle, and use the hit rate of landing inside the band to estimate the circumference. Implement this strategy in a function For example: Note:
You should not hard-code any formulas involving a circle's circumference or area.
However, you may wish to calculate distance between two points or from the origin.
It is up to you what size square to use.estimate_circumference(radius, num_darts), whose docstring is given below.
You may assume the random module is imported for you.def estimate_circumference(radius, num_darts):
"""
Run a "dart-throwing" Monte Carlo simulation to estimate the
circumference of a circle given its radius.
Parameters:
radius (float): The circle's radius.
num_darts (int): The number of "darts" to throw within a square
that encompasses such a circle.
Use the hit rate in the scheme described above to estimate the
circle's circumference, returning it as a float.
"""
estimate_circumference(10, 10_000) should, with very high probability, evaluate to within 62.8 +/- 5.estimate_circumference(10, 1_000_000) should, with very high probability, evaluate to within 62.8 +/- 0.5.