Description
Let π be a random variable that gives your winnings if you bet on red and the roulette wheel is spun once.
i). What is the probability distribution of π? Give your answer as a table.
ii). Calculate the expected value of your winnings by betting on red.
Write up your full solution in the SAME box below using LaTeX (not code). Show all steps fully justifying your answer.
i) We can use the Bernoulli Distribution to solve this as the wheel is spun only one time. We see that we
have chance of landing on red, and is not.
X 1 β1
Prob
ii)
Expected value of winnings by betting on red is:
β =
2
0.0.2 Question 2b)
Letβs simulate this. In the first code box below, write code to simulate one spin of a roulette wheel. Your output should be a string in the form of the number then the color (i.e. 18R or 00G)
In the 2nd code box below, write code that takes the number of spins and either the color red or black as input, calculates winnings for each spin assuming you bet on that color for all spins, and then outputs the average winnings out of those spins.
Then run the simulation 3 different times for num_spins = 100,000 and compare to your answer from part A.
To receive credit you must write your code such that all lines are visible in your PDF output.
In [20]: wheel = [
‘0G’,’32R’,’15B’,’19R’,’4B’,’21R’,’2B’,’25R’,’17B’,’34R’,
‘6B’,’27R’,’13B’,’11B’,’30R’,’8B’,’23R’,’10B’,’5R’,’24B’,
’16R’,’33B’,’1R’,’20B’,’14R’,’31B’,’9R’,’22B’,’18R’,’29B’,’7R’,
’28B’,’7R’,’12R’,’35B’,’3R’,’26B’,’00G’
] def spin_roulette():
return np.random.choice(wheel) # Your code above this line
spin_roulette()
Out[20]: ’12R’
In [21]: def color_winnings(color=’R’, num_spins=100000): total = 0 for i in range(num_spins):
if spin_roulette()[-1] == color:
total += 1 else:
total -=1
average_winnings = (total)/ num_spins return average_winnings
print(“E[Winnings] = {:.3f}”.format(color_winnings(color=”R”, num_spins=int(1e6)))) print(“E[Winnings] = {:.3f}”.format(color_winnings(color=”R”, num_spins=int(1e6)))) print(“E[Winnings] = {:.3f}”.format(color_winnings(color=”R”, num_spins=int(1e6))))
E[Winnings] = -0.054
E[Winnings] = -0.054
E[Winnings] = -0.053
4
0.0.3 Question 2c)
In Roulette you can bet on one of three βdozensβ segments, called 1st 12, 2nd 12, and 3rd 12. They cover 1-12, 13-24, and 25-36, respectively. If you bet $1 on the first dozen (or second dozen, or third dozen) nonzero numbers and win, then you win $2 (i.e. you get your original dollar back, plus another $2.
Let π be a random variable that gives your winnings if you bet on any one of the three βdozenβ nonzero numbers and the roulette wheel is spun once.
i). What is the probability distribution of π ? Give your answer as a table.
ii). What is πΈ[π ]?
Write up your full solution in the SAME box below using LaTeX (not code). Show all steps fully justifying your answer.
i)
Since there are for winning, we know that the probability of losing is 1 β =
Y 2 β1
Prob
ii)
6
0.0.4 Question 2d)
Write code to simulate num_spins spins, record the winnings for each spin if you bet on the first dozen nonzero numbers, and calculate the average winnings out of the total spins.
Then run the simulation 3 different times for num_spins = 100,000 and compare to your answer from part C.
In [22]: def dozen_winnings(num_spins): total_d = 0 for i in range(num_spins):
if 1 <= int(spin_roulette()[:-1]) <= 12: total_d += 2
else:
total_d -= 1
return (total_d/num_spins) # Your code above this line
print(“E[Winnings] = {:.3f}”.format(dozen_winnings(num_spins=100000))) print(“E[Winnings] = {:.3f}”.format(dozen_winnings(num_spins=100000))) print(“E[Winnings] = {:.3f}”.format(dozen_winnings(num_spins=100000)))
E[Winnings] = 0.028
E[Winnings] = 0.023
E[Winnings] = 0.029
8 ### Question 2e) ###
Recall, we showed in class that the expected winnings if you bet on any number is also β .
So youβre hopefully onto the pattern by now. The payouts in Roulette are designed so that the expected payout for a winning bet is always β .
Since we define these payouts in terms of your winnings after betting $1, we can think of these as payout odds.
For example, since if you bet $1 on the first dozen nonzero numbers and win, then you win $2, we say the odds are 2 to 1 (denoted 2:1).
The odds are 35:1 for landing on any particular number. This means if you bet $1, youβll win $35.
Suppose the casino wanted to develop odds for a new bet in Roulette, where they allow you to bet on any set of 3 different numbers. Let the odds for this new bet be
π₯ βΆ 1
What should π₯ be so that the expected payout for a winning bet is still β ?.
Show your work using LaTeX below.
2e)
We have πΈπ = (
We can set πΈπ =
= 338π₯ β 1 +
= 338π₯ +
β = 338π₯
= 338π₯
Thus we can show that x = 11
10 ### Question 2f) ###
Letβs generalize this!
Define a function π₯(π) that describes the odds the casino should give for betting $1 on any set of π numbers if the casino wants to keep the expected payout for a winning bet at β for any π. (For example, the odds for betting on any 3 different numbers should be set at π₯(3) to 1. The odds for betting on any 4 different numbers should be set at π₯(4) to 1).
πΈπ = ( π
We can set πΈπ =
= ππ₯38 + 38π
β 38π = ππ₯38
36β38π = ππ₯38
π₯ = 36βπ π
Thus we see that π₯ = 36βπ π
We can also prove that this works by setting π = 3.
π₯ = = 11, which shows us that 2e) is correct.
12 Answer all of the parts below in the SAME cell below using LaTeX. Show all of your steps.
3a). Determine the value of π such that this defines a valid probability distribution. Use that value for the rest of the problem.
3b). Calculate π(π β€ 3).
3c). What is πΈ[π]? (Show steps calculating this).
3d). What is the standard deviation of π? (Show all steps calculating this).
Answer all of the parts above in SINGLE cell provided below using LaTeX. 3a)
We want the the probability distribution to be = 1, so we plug in the sum of probabilities of k = 2,3,4.
$ = 2a((2^2 -2) + (3^2 – 3) + (4^2 -4))$ $ = 2a 20$
We set it equal to 1
40π = 1
π =
3b)
To satisfy π(π β€ 3), we have k = 3, 2.
We have 402 π2 β 402 π
(402 32 β 402 3) + (402 22 β 402 2) = + =
3c)
(π₯2π(π = π₯))
= = =
3d)
The standard deviation of X:
π ππ(π) = πΈ[π2] β (πΈ[π])2
We know what πΈ[π] is from 3c, thus we can solve for πΈ[π2].
πΈ[π2] = β4π=2 π₯2(π(π = π₯))
πΈ[π
=
Thus: π ππ(π) = πΈ[π2] β (πΈ[π])2 = β (72)2 = β = .
Finally we show that the standard deviation is:
π = βπ ππ(π) = β(πΈ[π2] β (πΈ[π])
14
0.0.5 Question 3e
Plot a histogram of the discrete probability distribution for π.
Use the same plotting guidelines as shown in Problem 1 so we can interpret area in the histogram as representing probability: – Set the bin widths to be equal to 1 – Add white lines between each bar Be sure to include a title on your plot.
In [25]: k = np.array([2,3,4]) p = (1/20 * k**2 – 1/20 *k)
fig, ax = plt.subplots() ax.bar(k,p, width= 1, ec = ‘white’);
ax.set_axisbelow(True) ax.grid(alpha = 0.25) plt.title(“Discrete Probability Distribution for X”)
# Your code for the histogram above this line
Out[25]: Text(0.5, 1.0, ‘Discrete Probability Distribution for X’)
16 Answer all of the parts below in the SAME cell below using LaTeX. Show all of your steps.
4a). What is the probability that exactly 6 customers pass through Johnβs line in the next 10 minutes?
4b). What is the probability that exactly 6 customers pass through the self check-out in the next 10 minutes, assuming that it is working?
4c). What is the probability that exactly 6 customers pass through the self check-out in the next 10 minutes, assuming that it is frozen?
4d). Use your results from 4b and 4c and the Law of Total Probability to calculate the probability that the self check-out tends exactly 6 customers in the next 10 minutes. Show all steps using LaTeX.
Answer all of the parts above in SINGLE cell provided below using LaTeX.
4a) The probability of π customers that pass through a line in the next 10 minutes, where the average rate of customer arrival is π can be demonstrated by the Poisson Distribution
π(π = π) = πβππ!β
ππ
Thus we can show when exactly 6 customers pass through:
For Johnβs line π = 4,π = 6.
π(π = 6) = πβ46!β
46 β 0.104
4b)
The self checkout line is π = 5,π = 6.
π(π = 6) = πβ56!β
56 β 0.146
4c)
When it is freezing, the self checkout machine is π = 1,π = 6
π(π = 6) = πβ16!β
16 β 0.0005
4d)
The probability that the self checkout tends exaclty 6 customers is:
We multiplied by 0.1 for the freezing as this has a probability of 0.1 when freezing up.
0.0.6 Question 4e)
Plot a histogram of the probability distribution of the number of customers he serves in his 5 hour shift. For the domain of the histogram, include π₯ values between 75 and 160 in your plot.
Hint: Python has a built-in function to calculate the Poisson distribution for different values of π. See the documentation for poisson.pmf in scipy.stats
(https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.poisson.html)
Hint: Since we are changing the time interval over which we are counting customers, you will need to update the parameter π in the Poisson distribution to be the average number of customers John can serve in a 5-hour shift. You can assume that his rate of 4 customers per 10 minutes scales up consistently during his 5 hour shift.
In [28]: from scipy.stats import poisson
In [29]: x = np.arange(75,161) rate_of_customer_10 = 4 time_five_hour_shift_divided = 30
p = poisson.pmf(x, rate_of_customer_10 * time_five_hour_shift_divided)
fig,ax = plt.subplots() ax.bar(x, p, width = 1 , ec = ‘white’) ax.grid(alpha = 0.25) plt.title(“Discrete Probability Distribution for Customers John can serve in a 5 hour shift”) plt.xlabel(“Served Customer”) plt.ylabel(“Probability”)
# your code above this line Out[29]: Text(0, 0.5, ‘Probability’)
0.0.7 Question 4g)
Time to simulate!
Recall from lecture that if the number of random events follows a Poisson distribution, the lapse of time between these events follows an Exponential distribution. For example, if the number of occurrences per 10 minute interval is distributed π~ ππππ (4), then the time (in units of 10 minutes) between arrivals is π ~
πΈπ₯π(4).
Weβre going to simulate the number of customers served using this knowledge.
i). Write a function checkout_count to simulate the number of customers served by the self check-out machine in a 5-hour shift.
Your function should take as input the time length time_len, for calculating the arrivals, the working and broken customer arrival rate parameters (based on the time length given), and the probability, p that the machine is working properly.
Your function should simulate customer arrival times at the front of the line by sampling between-customer times from πΈπ₯π(π) via Numpyβs random.exponential function, where the argument π will depend on the state of the machine (working or broken). Read the documentation carefully for the format of the input for the exponential function in Numpy.
Your simulation should model the arrival of each new customer, and sample whether or not the machine is working properly for each new customer.
Your function should return the number of customer arrivals in a 5-hour shift.
Make sure all code is visible in your PDF, or you wonβt receive points for this problem
ii). Use 10,000 simulations of this function to estimate the probability of the self check-out machine serves 100 or more customers in a 5-hour shift, and report your result. iii). Finally, use 10,000 simulations of this same function to verify your answer to Part 4e.
In [32]: def checkout_count(time_len, rate_work, rate_broken, p):
”’
time_len = time interval (minutes) rate_work = rate when machine is working (customers/time unit)
rate_broken = rate when machine is broken (customers/time unit) p = probability machine is working
”’ customer = 0 total_time = 0 while total_time <= time_len: rate = np.random.choice([rate_work, rate_broken], p=[p, 1-p]) next_arrive = np.random.exponential(1/rate) total_time += next_arrive
if total_time <= time_len: customer += 1 return customer
checkout_count(10,5,1,0.9)
Out[32]: 48
In [33]: Hundred_serve = 0 for x in range(10000):
if checkout_count(300, .5, .1, 0.9) >= 100:
Hundred_serve += 1 print(Hundred_serve/10000)
# Your code for part ii above this line
# Output should be approximately 0.70 if code is correct.
0.6972
In [34]: Hundred_serve1 = 0 for x in range(10000):
if checkout_count(300, .4, 0, 1) >= 100:
Hundred_serve1 += 1 print(Hundred_serve1/10000)
# Your code for part iii above this line
# Output should match your theoretical answer to Part 4f
0.9751
QUESTION 4h: Comment on the results you found above in Parts F and G comparing the probabilities that John and the self check-out machine will serve 100 or more customers in a 5-hour block. Which seems like a better investment for the grocery store? Justify your answer.
We see that John will be a good investment. John has a probability of 0.9715 while the self checkout machine has a probability of 0.6972. This shows that John will serve 100 or more customers in a 5 hour interval 97.15% of the time, while self checkout will only serve 69.72%
24
Reviews
There are no reviews yet.