1

building_a_tennis_match_simulator_in_python2

 2 years ago
source link: https://gist.github.com/mjam03/0de6fae55bf93e8d2f75bba13012598b
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
building_a_tennis_match_simulator_in_python2 · GitHub

Instantly share code, notes, and snippets.

building_a_tennis_match_simulator_in_python2

games = 100 sims = 1000 probabs = np.linspace(0.5, 0.8, 4) results = {}

# for each server probability for p in probabs: # we now need to generate 1000 sims means = [] game_lengths = [] for i in range(0, sims): g_results = [sim_game(p) for x in range(games)] # get mean result mean_res = np.mean([x[0] for x in g_results]) # get mean game length mean_length = np.mean([len(x[1]) for x in g_results]) # join to results holders means.append(mean_res) game_lengths.append(mean_length) # add data to probab dict results[p] = (means, game_lengths)

# plot the mean server win percentage fig, axes = plt.subplots(ncols=2, nrows=2, figsize=(30,20)) axes = axes.reshape(-1)

xlims = (min([min(x[0]) for x in results.values()]), 1)

for data, ax in zip(results.items(), axes): # grab the means means = data[1][0] # plot them sns.distplot(means, ax=ax) ax.set_xlim(xlims) ax.set_title('Server Game Win Distribution, p: {:,.2%}'.format(data[0])) ax.set_xlabel('Server Game Win Probability') ax.set_xticklabels(['{:,.1%}'.format(x) for x in ax.get_xticks()]);


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK