- Jupyter for Data Science
- Dan Toomey
- 210字
- 2021-07-08 09:22:34
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).
推薦閱讀
- Facebook Application Development with Graph API Cookbook
- Node.js 10實戰
- C語言程序設計習題解析與上機指導(第4版)
- Python自然語言處理實戰:核心技術與算法
- Learning ASP.NET Core 2.0
- Practical Game Design
- Python算法從菜鳥到達人
- 快人一步:系統性能提高之道
- Node.js全程實例
- Terraform:多云、混合云環境下實現基礎設施即代碼(第2版)
- Access 2010中文版項目教程
- Clojure for Java Developers
- Maker基地嘉年華:玩轉樂動魔盒學Scratch
- Android高級開發實戰:UI、NDK與安全
- 企業級Java現代化:寫給開發者的云原生簡明指南