Created
September 22, 2021 10:03
-
-
Save iggisv9t/50744dfeff2eb338b74f6566b852ee23 to your computer and use it in GitHub Desktop.
Partymaker
This file contains 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
def one_run(max_size, max_iters, p, q, disable=False): | |
max_idea = 0 | |
run_times = [] | |
for size in tqdm(range(max_size), disable=disable): | |
ideas = [None for i in range(size)] + [None] | |
condition = True | |
run_time = 0 | |
while condition: | |
run_time += 1 | |
new_ideas = [a for a in ideas] | |
for i, idea in enumerate(ideas): | |
action = np.random.choice(['accept', 'decline', 'new'], p=[p, q, (1 - p - q)]) | |
if action == 'accept': | |
new_ideas[i] = np.random.choice(ideas) | |
if action == 'decline': | |
new_ideas[i] = ideas[i] | |
if action == 'new': | |
max_idea += 1 | |
new_ideas[i] = max_idea | |
ideas = new_ideas | |
condition = (not ((len(set(ideas)) == 1) and (not (ideas[0] is None)))) and (run_time < max_iters) | |
run_times.append(run_time) | |
return run_times | |
### Sample | |
NRUNS = 10 | |
results = [] | |
for p in tqdm(np.linspace(0.05, 0.95, 20)): | |
for q in np.linspace(0, 0.95, 20): | |
if p + q < 1: | |
for _ in range(NRUNS): | |
results.append([p, q] + one_run(50, 800, p, q, disable=True)) | |
# Make DataFrame | |
results_df = pd.DataFrame(results, columns=['p', 'q'] + ['size_{}'.format(i) for i in range(50)]) | |
grouped = results_df.groupby(['p', 'q']).mean().reset_index() | |
# Draw Results | |
col = 'size_10' | |
plt.figure(figsize=(10, 10)) | |
plt.scatter(grouped['p'].values, grouped['q'].values, | |
grouped[col].values, marker='.', | |
c=grouped[col].values, | |
cmap='rainbow'); | |
plt.title(col.replace('_', ': ')) | |
plt.xlabel('Acceptance Rate') | |
plt.ylabel('Rejection Rate') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment