Created
January 3, 2020 17:20
-
-
Save bbrelje/2451ea9ec921e7a0ef7e4210df6328a7 to your computer and use it in GitHub Desktop.
Plots for computing optimal strategy in winner-take-all games with many opponents
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
from __future__ import division | |
from matplotlib import pyplot as plt | |
import numpy as np | |
sigma_mine = 2.0 | |
sigma_they = 1.0 | |
mean_mine = 0.3 | |
mean_they = 0.0 | |
N_other_players = 4 | |
N_samples = 100000 | |
if __name__ == "__main__": | |
win_count = 0 | |
for i in range(N_samples): | |
other_player_scores = np.random.normal(mean_they, sigma_they, (N_other_players)) | |
my_score = np.random.normal(mean_mine, sigma_mine) | |
if my_score >= np.max(other_player_scores): | |
win_count += 1 | |
win_pct = win_count / N_samples | |
print(win_pct) |
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
from __future__ import division | |
from scipy import integrate | |
from scipy.stats import norm | |
import numpy as np | |
import plotly.graph_objects as go | |
def myfunc(x, mu, sigma, N): | |
pdf = norm.pdf(x, loc=mu, scale=sigma) | |
dpdf_dsigma = (x-mu)**2 / sigma **3 * pdf - pdf / sigma | |
f = norm.cdf(x)**N * dpdf_dsigma | |
return f | |
if __name__ == "__main__": | |
mu = 0.3 | |
sigma = 2.0 | |
N = 1 | |
mus = np.linspace(-1.0, 3.0, 21) | |
Ns = np.linspace(1.0, 200.0, 20) | |
probs = [] | |
for i in range(21): | |
probs.append([]) | |
for j in range(20): | |
args = (mus[i], 1.0, Ns[j]) | |
probs[i].append(integrate.quad(myfunc, -np.inf, np.inf, args=args)[0]) | |
colorscale = [[0, 'black'], [1, 'black']] | |
fig = go.Figure(data = | |
go.Contour( | |
z=probs, | |
x=Ns, # horizontal axis | |
y=mus, # vertical axis | |
contours=dict(start=0,end=0,size=1), | |
contours_coloring='lines', | |
colorbar=None, | |
colorscale=colorscale, | |
line_width=5, | |
)) | |
fig.update_layout( | |
title="High/low-variance strategy breakeven", | |
xaxis_title=r"$\text{Opponent count} \, (N)$", | |
yaxis_title=r"$\text{Player normalized skill} \, (\frac{\mu_0-\mu}{\sigma})$", | |
showlegend=False, | |
font=dict( | |
size=18, | |
color="#7f7f7f") | |
) | |
fig.show() |
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
from __future__ import division | |
from scipy import integrate | |
from scipy.stats import norm | |
import numpy as np | |
import plotly.graph_objects as go | |
def myfunc(x, mu, sigma, N): | |
f = norm.cdf(x)**N * norm.pdf(x, loc=mu, scale=sigma) | |
return f | |
if __name__ == "__main__": | |
mu = 0.3 | |
sigma = 2.0 | |
N = 5 | |
mus = np.linspace(-2.0, 2.0, 20) | |
sigmas = np.linspace(0.1, 3.0, 20) | |
probs = [] | |
for i in range(20): | |
probs.append([]) | |
for j in range(20): | |
args = (mus[i], sigmas[j], N) | |
probs[i].append(integrate.quad(myfunc, -np.inf, np.inf, args=args)[0]) | |
fig = go.Figure(data = | |
go.Contour( | |
z=probs, | |
x=sigmas, # horizontal axis | |
y=mus # vertical axis | |
)) | |
fig.update_layout( | |
title="Win Probability with N="+str(N)+" opponents", | |
xaxis_title=r"$\text{Player variability} \, (\sigma_0)$", | |
yaxis_title=r"$\text{Player normalized skill} \, (\frac{\mu_0-\mu}{\sigma})$", | |
font=dict( | |
size=18, | |
color="#7f7f7f")) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment