Two gamblers A and B are successively playing a game until one wins all the money and the other is ruined (goes bankrupt). There is a sequence of rounds, with a one dollar bet each time. The rounds are independent events. Let p=P(A wins a certain round) and the inverse is q=1−p, by convention.
What is the probability that A wins the entire game?
Some clarifications:
But where do we begin to solve this problem?
A random walk between two points on a number line is very similar to the Gambler's Ruin.
How many rounds could a game last? Is it possible for the game to continue on to infinity?
Well, notice how this has a very nice recursive nature. If A loses a round, the game can be seen as starting anew at i−1, and if he wins, the game would start anew at i+1. It is the same problem, but with a different starting condition.
Conditioning on the first step is called first step analysis.
Let Pi=P(A wins the entire game|A starts with i dollars). Then from the Law of Total Probability, we have:
Pi=pPi+1+qPi−1, where 1<i<N−1P0=0PN=1See how this is a recursive equation? This is called a difference equation, which is a discrete analog of a differential equation.
Assuming an unfair game where p=0.49, q=0.51:
import math
def gamblers_ruin(i, p, q, N):
if math.isclose(p,q):
return i/N
else:
return ((1 - (q/p)**i)) / (1 - (q/p)**N)
p = 0.49
q = 1.0 - p
N = 20
i = N/2
print("With N={} and p={}, probability that A wins all is {:.2f}".format(N, p, gamblers_ruin(i, p, q, N)))
N = 100
i = N/2
print("With N={} and p={}, probability that A wins all is {:.2f}".format(N, p, gamblers_ruin(i, p, q, N)))
N = 200
i = N/2
print("With N={} and p={}, probability that A wins all is {:.2f}".format(N, p, gamblers_ruin(i, p, q, N)))
With N=20 and p=0.49, probability that A wins all is 0.40 With N=100 and p=0.49, probability that A wins all is 0.12 With N=200 and p=0.49, probability that A wins all is 0.02
And assuming a fair game where p=q=0.5:
p = 0.5
q = 1.0 - p
N = 20
i = N/2
print("With N={} and p={}, probability that A wins all is {:.2f}".format(N, p, gamblers_ruin(i, p, q, N)))
N = 100
i = N/2
print("With N={} and p={}, probability that A wins all is {:.2f}".format(N, p, gamblers_ruin(i, p, q, N)))
N = 200
i = N/2
print("With N={} and p={}, probability that A wins all is {:.2f}".format(N, p, gamblers_ruin(i, p, q, N)))
With N=20 and p=0.5, probability that A wins all is 0.50 With N=100 and p=0.5, probability that A wins all is 0.50 With N=200 and p=0.5, probability that A wins all is 0.50
Recall that we have the following solution to the difference equation for the Gambler's Ruin game:
Pi={1−(qp)i1−(qp)N if p≠qiN if p=qThe only time you'd think the game could continue on to infinity is when p=q. But
P(Ω)=1=P(A wins all)+P(B wins all)=Pi+PN−i=iN+N−iNThe above implies that aside from the case where A wins all, and the case where B wins all, there is no other event in Ω to consider, hence the game can never continue on to infinity without either side winning.
This also means that unless p=q, you will lose your money, and the only question is how fast will you lose it.
Consider these statements:
x+2=9x=7What is a variable?
What is a random variable?
Here are a few of the most useful discrete random variables.
A probability distribution of a random variable that takes the value 1 in the case of a success with probability p; or takes the value 0 in case of a failure with probability 1−p.
A most common example would be a coin toss, where heads might be considered a success with probability p=0.5 if the coin is a fair.
A random variable x has the Bernoulli distribution if
X∼Bern(p)
0<p<1, p∈R
The probability mass function P(x) over possible values x
P(x)={1−p, if x=0p, if x=1import matplotlib
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,
AutoMinorLocator)
from scipy.stats import binom
%matplotlib inline
plt.xkcd()
_, ax = plt.subplots(figsize=(12,8))
# a few Binomial parameters n and p
pop_sizes = [240, 120, 60, 24]
p_values = [0.2, 0.3, 0.4, 0.8]
params = list(zip(pop_sizes, p_values))
# colorblind-safe, qualitative color scheme
colors = ['#a6cee3','#1f78b4','#b2df8a','#33a02c']
for i,(n,p) in enumerate(params):
x = np.arange(binom.ppf(0.01, n, p), binom.ppf(0.99, n, p))
y = binom.pmf(x, n, p)
ax.plot(x, y, 'o', ms=8, color=colors[i], label='n={}, p={}'.format(n,p))
ax.vlines(x, 0, y, color=colors[i], alpha=0.3)
# legend styling
legend = ax.legend()
for label in legend.get_texts():
label.set_fontsize('large')
for label in legend.get_lines():
label.set_linewidth(1.5)
# y-axis
ax.set_ylim([0.0, 0.23])
ax.set_ylabel(r'$P(x=k)$')
# x-axis
ax.set_xlim([10, 65])
ax.set_xlabel('# of successes k out of n Bernoulli trials')
# x-axis tick formatting
majorLocator = MultipleLocator(5)
majorFormatter = FormatStrFormatter('%d')
minorLocator = MultipleLocator(1)
ax.xaxis.set_major_locator(majorLocator)
ax.xaxis.set_major_formatter(majorFormatter)
ax.grid(color='grey', linestyle='-', linewidth=0.3)
plt.suptitle(r'Binomial PMF: $P(x=k) = \binom{n}{k} p^k (1-p)^{n-k}$')
plt.show()
Now think about this true statement as we move on to Lecture 3:
X∼Bin(n,p), Y∼Bin(m,p)→X+Y∼Bin(n+m,p)To solve for for the case where p=q, let x=qp.
limx→11−xi1−xN=limx→1ixi−1NxN−1 by l'Hopital's Rule=iNView Lecture 7: Gambler's Ruin and Random Variables | Statistics 110 on YouTube.