贝塔分布 beta分布的累积分布函数(CDF)计算 —— 如何使用二项式分布表示beta分布的概率累积函数
贝塔分布 beta分布的累积分布函数(CDF)的计算公式:
计算beta分布的累积分布函数(CDF)是需要计算积分的,但是最近发现另一种计算方法,即,使用二项式分布计算beta分布的概率累积函数。
beta分布:事件发生概率p,事件发生次数a,事件未发生次数b,总次数n=a+b。
beta(p, a, b) = Prob(P=p)
Prob(p1<P<p2) = beta.cdf(p2, a, b) - beta.cdf(p1, a, b) = sum(combination(a+b-1, x) * (p2 ** x) * ((1-p2) ** (a+b-1-x))-combination(a+b-1, x) * (p1 ** x) * ((1-p1) ** (a+b-1-x)) for x in range(a, a+b))
import math
from scipy.stats import beta
# n = 20
# x = 6
p1 = 0.5
p2 = 0.1
def binomial_cdf(p, n, x):
return sum(math.comb(n-1, i)*(p**i)*((1-p)**(n-1-i)) for i in range(x, n))
for (n, x) in [(20, 10), (20, 9),(20, 8),(20, 7),(20, 6), (20, 5), (20, 4),(20, 3),(20, 2),(20, 1),]:
print(binomial_cdf(p1, n, x) - binomial_cdf(p2, n, x), beta.cdf(p1, x, n-x)-beta.cdf(p2, x, n-x))
运行结果:
使用二项分布计算Beta分布的区间值。
本博客是博主个人学习时的一些记录,不保证是为原创,个别文章加入了转载的源地址,还有个别文章是汇总网上多份资料所成,在这之中也必有疏漏未加标注处,如有侵权请与博主联系。
如果未特殊标注则为原创,遵循 CC 4.0 BY-SA 版权协议。
posted on 2024-08-01 19:37 Angry_Panda 阅读(118) 评论(0) 编辑 收藏 举报