Created
February 25, 2021 23:42
-
-
Save 3catz/82455129b3a1776e5d5e9a7c15a0eb4b to your computer and use it in GitHub Desktop.
Secretary Problem simulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n_trials = 10000 | |
n_candidates = 100 | |
max_burn = int(0.66 * n_candidates) | |
for T in range(1, max_burn, 5): | |
global_maxes = [] | |
diff_from_max = [] | |
time_taken = [] | |
final_choices = [] | |
for i in range(n_trials): | |
candidates = np.random.poisson(lam = 100, size = n_candidates) | |
#candidates = weib.random_samples(100).round() | |
np.random.shuffle(candidates) | |
global_max = np.max(candidates) | |
global_maxes.append(global_max) | |
pool = candidates[:T] | |
remainder = candidates[T:] | |
pool_max = np.max(pool) | |
thresh = np.quantile(pool, q = 1.0) | |
for i in range(len(remainder)): | |
#print(i) | |
if remainder[i] > thresh: | |
time_taken.append(T + i) | |
diff = global_max - remainder[i] | |
diff_from_max.append(diff) | |
final_choices.append(remainder[i]) | |
break | |
print("Total Candidates:", n_candidates, "|| Burn in Period = ", T, "|| Trials = ", n_trials) | |
print("Average Global Max = {:.2f}".format(np.mean(global_maxes))) | |
print("Average Choice = {:.2f}".format(np.mean(final_choices))) | |
print("Average diff from max {:.2f}".format(np.mean(diff_from_max)), "| Average time taken {:.2f}".format(np.mean(time_taken))), #"| Efficiency {:.2f}".format(np.mean(time_taken/np.mean(diff_from_max)))) | |
print("------------------------------------------------------------------------------------------------------") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment