This part considers how the probaiblity of winning may change with a different distribution of breakup day and minute.
This notebooks is particularly useful for Question 2 of the report.
%load_ext autoreload
%autoreload 2
import os
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
from tools import *
pickle_path = os.path.join('pickles',
'tickets_per_minute.pkl')
with open(pickle_path, 'rb') as f:
loaded_radial_dist_list = pickle.load(f)
Task 1:
Run this cell to reset the probability model with a new distribution of the breakup day. Note that the pickle file is reset and rebuilt, which takes around 20-30 seconds.
Running this cell will delete the pickle file and change the calculations in Notebooks 1 and 2. Make sure you reset the pickle file before rerunning those notebooks, or do this on a separate computer from group members who are working on Notebooks 1 and 2. To reset the pickle file to the "original" value simply run the cell below without the keyword argument that overrides the moments.
Models.reset_prob_pickle()
m = Models(moments_day=(20, 6.5))
m.plot(0)
Task 2:
Once you have a new probability model, you can do a new simulation for whatever set of tickets you like to see if you can improve your chances of winning, based on the new model.
t = Tickets()
t.add([[15]])
# t.add([[27, 28, 29]])
# t.add([[14], [13]])
t.status()
t.show()
m = Models()
prob_T = np.zeros((len(t.tickets)))
Nw_T = np.zeros((len(t.tickets)))
for i, ti in enumerate(t.tickets):
prob_T[i] = m.get_p([ti])
day, min = Minutes.get_day_min(ti)
Nw_T [i] = m.ticket_model(day, min)
prob_T_matrix = m.map_data_to_day_min(prob_T, t.tickets)
prob_all = np.sum(prob_T)
print(f"The probability of any ticket winning is {prob_all:.3e}")
cost_tickets = len(t.tickets)*3
expected_winnings = np.sum(300*prob_T/(Nw_T + 1))
expected_profit = expected_winnings - .003*len(t.tickets)
print(f"Number of tickets: \t{len(t.tickets)}")
print(f"Cost tickets: \t\t{cost_tickets/1000:9.2e} kUSD \t({len(t.tickets)*3:5.0f} USD)")
print(f"Expected winnings: \t{expected_winnings:9.2e} kUSD \t({expected_winnings*1000:5.0f} USD)")
print(f"Expected profit: \t{expected_profit:9.2e} kUSD \t({expected_profit*1000:5.0f} USD)")
m.plot(prob_T_matrix)
Ns = 100000
sampled_ticket = np.zeros((Ns,), dtype=int)
sampled_probability = np.zeros((Ns,))
sampled_winnings = np.zeros((Ns,))
for i in range(Ns):
sampled_ticket[i] = random.choices(t.tickets, weights=prob_T, k=1)[0]
sampled_probability[i] = prob_T[
t.tickets.index(sampled_ticket[i])]
sampled_winnings[i] = 300/(1 + sample_integer(
loaded_radial_dist_list[sampled_ticket[i]]))
plot_hist_and_cdf(sampled_winnings,
xlim=(1,500), ylim=(1e-2, 1))
print("=====================================")
print(" USING EXPECTED VALUE CALC ")
print("=====================================")
print(f"Number of tickets: \t{len(t.tickets)}")
print(f"Cost tickets: \t\t{cost_tickets/1000:9.2e} kUSD \t({len(t.tickets)*3:5.0f} USD)")
print(f"Expected winnings: \t{expected_winnings:9.2e} kUSD \t({expected_winnings*1000:5.0f} USD)")
print(f"Expected profit: \t{expected_profit:9.2e} kUSD \t({expected_profit*1000:5.0f} USD)")
End of notebook.