Python modules. Random numbers: module random functions uniform and normalvariate. Plotting: module matplotlib. ...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Python modules. • Random numbers: module random functions uniform and normalvariate. • Plotting: module matplotlib. • Simple deterministic, discrete-time SIR model of an epidemic. Refresher problems. Before the coronabreak, we covered the use of modules, especially the broadly useful random and matplotlib. Here, we will explore basic randomness concepts by first simulating random processes that you are familiar with (coin tosses and dice), and then numerically and graphically summarizing them. 1. In class we used the random uniform distribution, implemented in random.uniform, to simulate a coin. import random def coin_flip(): """Coin-flip using uniform distribution. """ if random.uniform(0, 1) < 0.5: return 'Heads' else: return 'Tails' a. Now, instead, write a function named coin_flips to conduct an arbitrary number of simulated coin flips, using the random normal distribution (random.normalvariate). Unlike the example given above, your function should take one argument named n, indicating the number of coin- flips, and return a list of length n, with appropriate string values ('Heads' or 'Tails'). Your function should begin with a docstring and then immediately set a random seed (using the random.seed function) with your UIC ID as the random seed number. b. Run your function with n 100, n 10000, and n 1000000. Plot a histogram of the frequency with which each of the two sides was drawn (from your coin-flip results), for each of the three cases. 2. a. Write a function named die toss to make a virtual six-sided die in Python. Your function should take one argument named n, indicating the number of die-tosses, and return a list of length n, with appropriate integer values (1, 2, 3, 4, 5, and 6). Your function should begin with a docstring and then immediately set a random seed (using the random.seed function) with your UIC ID as the random seed number. b. Run your function with n = 100, n 1000o, and n = 1000000. Plot a histogram of the frequency with which each of the six sides was drawn (from your toss results), for each of the three cases. 3. The following problem will rely on a simple implementation of the SIR model we covered in class, shown below as the function corona_sim: def corona_sim (beta, gamma, t): nn"Simple deterministic, discrete-time SIR model."u # Initial population fractions of: (i)nfectious (s)ucceptible (r) emoved i = 0.001 #3 #3 %23 S = 1 - i r = 0 # Initialize lists where we will store s, i, and r values over time. s_at_t = [s] i_at_t = [i] r_at_t = [r] # The meat of the function, where changes are calculated # for each time-step (0 through t). for d in range (1, t): s diff = beta * s * i r_diff = gamma * i S = s - s diff i - i + s_diff r_diff r = r +r_diff s_at t.append (s) i_at_t.append (i) r_at_t.append (r) return s_at_t, i_at_t, r_at_t If, in the absence of social distancing strategies, the parameter beta = 0.30, and in the presence of such strategies, beta = 0.15. Assume that gamma = 0.1 in both cases and that the finite hospital resources can only treat i <= 0.05 proportion of the population (hospital capacity). Write a function overcap that takes two arguments: sir_results (the output of corona_sim function) and hcap (hospital capacity, as a fraction of the population). The function should return (i) the total fraction of the population that could not receive hospitalization (over capacity) and (ii) the number of time units during which capacity was exceeded. Run corona_sim with t 250 for both scenarios (distancing, no distancing). Then use your overcap function to calculate the overcapacity and time units for both scenarios. Python modules. • Random numbers: module random functions uniform and normalvariate. • Plotting: module matplotlib. • Simple deterministic, discrete-time SIR model of an epidemic. Refresher problems. Before the coronabreak, we covered the use of modules, especially the broadly useful random and matplotlib. Here, we will explore basic randomness concepts by first simulating random processes that you are familiar with (coin tosses and dice), and then numerically and graphically summarizing them. 1. In class we used the random uniform distribution, implemented in random.uniform, to simulate a coin. import random def coin_flip(): """Coin-flip using uniform distribution. """ if random.uniform(0, 1) < 0.5: return 'Heads' else: return 'Tails' a. Now, instead, write a function named coin_flips to conduct an arbitrary number of simulated coin flips, using the random normal distribution (random.normalvariate). Unlike the example given above, your function should take one argument named n, indicating the number of coin- flips, and return a list of length n, with appropriate string values ('Heads' or 'Tails'). Your function should begin with a docstring and then immediately set a random seed (using the random.seed function) with your UIC ID as the random seed number. b. Run your function with n 100, n 10000, and n 1000000. Plot a histogram of the frequency with which each of the two sides was drawn (from your coin-flip results), for each of the three cases. 2. a. Write a function named die toss to make a virtual six-sided die in Python. Your function should take one argument named n, indicating the number of die-tosses, and return a list of length n, with appropriate integer values (1, 2, 3, 4, 5, and 6). Your function should begin with a docstring and then immediately set a random seed (using the random.seed function) with your UIC ID as the random seed number. b. Run your function with n = 100, n 1000o, and n = 1000000. Plot a histogram of the frequency with which each of the six sides was drawn (from your toss results), for each of the three cases. 3. The following problem will rely on a simple implementation of the SIR model we covered in class, shown below as the function corona_sim: def corona_sim (beta, gamma, t): nn"Simple deterministic, discrete-time SIR model."u # Initial population fractions of: (i)nfectious (s)ucceptible (r) emoved i = 0.001 #3 #3 %23 S = 1 - i r = 0 # Initialize lists where we will store s, i, and r values over time. s_at_t = [s] i_at_t = [i] r_at_t = [r] # The meat of the function, where changes are calculated # for each time-step (0 through t). for d in range (1, t): s diff = beta * s * i r_diff = gamma * i S = s - s diff i - i + s_diff r_diff r = r +r_diff s_at t.append (s) i_at_t.append (i) r_at_t.append (r) return s_at_t, i_at_t, r_at_t If, in the absence of social distancing strategies, the parameter beta = 0.30, and in the presence of such strategies, beta = 0.15. Assume that gamma = 0.1 in both cases and that the finite hospital resources can only treat i <= 0.05 proportion of the population (hospital capacity). Write a function overcap that takes two arguments: sir_results (the output of corona_sim function) and hcap (hospital capacity, as a fraction of the population). The function should return (i) the total fraction of the population that could not receive hospitalization (over capacity) and (ii) the number of time units during which capacity was exceeded. Run corona_sim with t 250 for both scenarios (distancing, no distancing). Then use your overcap function to calculate the overcapacity and time units for both scenarios.
Expert Answer:
Answer rating: 100% (QA)
1 Code Screenshots Sample Output Files case1png case2png case3png Code to Copy Import the random module import random Import the matplotlib for plotting the histogram for the three cases import matplo... View the full answer
Related Book For
Posted Date:
Students also viewed these finance questions
-
You are familiar with the GAP, as a retailer currently undergoing changes to attract more customers. You have been given $150.00 to go shopping. Go to GAP online (www.gap.com) and go through the...
-
For each of the following schedule, state whether they are equivalent to some serial schedule (with respect to convict equivalence). In each case: if the answer is no, justify why it is not the case;...
-
Select an IT project that you are familiar with and comment on whether there was a formal project sponsor and champion, which business managers played these roles, and whether or not you think their...
-
As a bakery business continues to grow, cash flow has become more of a concern. The board of directors would like to maintain the market share price, so a discussion ensues about issuing a stock...
-
Snooker Arnovich buys on margin 1,000 shares of Rockford Systems stock at $60 per share. The initial margin requirement is 50% and the maintenance margin requirement is 30%. If the Rockford stock...
-
Using a graph, analyze the effect of technological advances that have increased workers productivity in the last few decades (e.g., the Internet) on the labor market. What will be the effect on the...
-
Below is a list of transactions completed by Recycled Fashion during 2024. Ignore GST. For each transaction, indicate (a) the section (i.e. operating, investing or financing) of the statement of cash...
-
Carney, Inc., has the following plant asset accounts: Land, Buildings, and Equipment, with a separate accumulated depreciation account for each of these except Land. Carney completed the following...
-
Consider a S corporation. The corporation earns $2.5 per share before taxes. The corporate tax rate is 35%, the tax rate on dividend income is 20%, and the personal income tax rate is set at 20%....
-
Wedding Planners Limited (WP), owned by Anne and Francois Tremblay, provides wedding planning and related services. WP owns a building (the Pavilion) that has been custom-made for hosting weddings....
-
Suppose a worker earns $40 an hour and commutes to work at a speed of 20 miles per hour (mph). The worker completes one round-trip daily to the downtown and commutes to work 20 days a month. How much...
-
(5.3) This exercise deals with deriving the money multiplier - relating high-powered money (the monetary base) to M1 (ignoring traveler's checks). Money demand for M1, Md, can be decomposed into the...
-
Use the central difference approximation formula to estimate the instantaneous rate of change of the daily receipts on day 70, millions / day The following table shows the daily receipts in millions...
-
A car travels at a speed of 50 km/h, but stops every 500 meters at a traffic light for 2 minutes. In how many minutes does the car cover a distance of 10 km?
-
Mr Apricot Angelfish is an Australian, born in Melbourne. Apricot is a one of the top Michelin Star chefs in the world and has been working in Hong Kong for 20 years. He is a permanent resident in...
-
Required information [The following information applies to the questions displayed below] Arndt, Incorporated reported the following for 2024 and 2025 ($ in millions): 2024 2025 Revenues $ 922 $...
-
One of the underlying principles of GAAP is that items on the balance sheet are listed at Book Value as opposed to Market Value. What are Book Value and Market Value? Under what circumstances could...
-
The Dow Jones Industrial Average reached a high of $ 7801.63 on December 29, 1997. Recall from Example 18.4 that it reached a high of $ 1003 on November 14, 1972. The Consumer Price Index for...
-
A researcher, believing to be no more than 0.40, calculates the necessary sample size for the confidence level and maximum likely error he has specified. Upon completing the study, he finds the...
-
A researcher has observed 100 shoppers from three different age groups entering a large discount store and noted the nature of the greeting received by the shopper. Given the results shown here, and...
-
For the following simple random sample of household incomes (thousands of dollars) from a large county, construct and interpret the 90% and 95% confidence intervals for the population mean. The data...
-
What type of signal is the output of a non-ICP accelerometer?
-
What are the negative aspects of using a seismic transducer?
-
Which industrial transducer does not require a power supply (selfgenerated signal)?
Study smarter with the SolutionInn App