官术网_书友最值得收藏!

Gambling, R - betting analysis

Some of the gambling games are really coin flips, with 50/50 chances of success. Along those lines we have coding from http://forumserver.twoplustwo.com/25/probability/flipping-coins-getting-3-row-1233506/ that determines the probability of a series of heads or tails in a coin flip, with a trigger that can be used if you know the coin/game is biased towards one result or the other.

We have the following script:

##############################################
# Biased/unbiased  recursion of heads OR tails
##############################################
import numpy as np
import math

N = 14     # number of flips
m = 3      # length of run (must be  > 1 and <= N/2)
p = 0.5   # P(heads)

prob = np.repeat(0.0,N)
h = np.repeat(0.0,N)
t = np.repeat(0.0,N)

h[m] = math.pow(p,m)
t[m] = math.pow(1-p,m)
prob[m] = h[m] + t[m]

for n in range(m+1,2*m):
  h[n] = (1-p)*math.pow(p,m)
  t[n] = p*math.pow(1-p,m)
  prob[n] = prob[n-1] + h[n] + t[n]


for n in range(2*m,N):
  h[n] = ((1-p) - t[n-m] - prob[n-m-1]*(1-p))*math.pow(p,m)
  t[n] = (p - h[n-m] - prob[n-m-1]*p)*math.pow(1-p,m)
  prob[n] = prob[n-1] + h[n] + t[n]

prob[N-1]  

The preceding code produces the following output in Jupyter:

We end up with the probability of getting three heads in a row with an unbiased game. In this case, there is a 92% chance (within the range of tests we have run 14 flips).

主站蜘蛛池模板: 阿拉善盟| 汝州市| 静宁县| 巨鹿县| 贺兰县| 苍梧县| 宣汉县| 宾川县| 潮州市| 舞钢市| 克拉玛依市| 开原市| 根河市| 禄劝| 仪陇县| 望江县| 神池县| 墨竹工卡县| 合肥市| 离岛区| 确山县| 昌图县| 信阳市| 吉木乃县| 济宁市| 万全县| 吉水县| 名山县| 广宁县| 九龙县| 平利县| 五家渠市| 昌邑市| 台州市| 兰考县| 普格县| 达尔| 林口县| 密山市| 石柱| 交口县|