Beta函数与Gamma函数及其与Beta分布的关系
来源:互联网 发布:淘宝网单人沙发床 编辑:程序博客网 时间:2024/05/18 02:41
相关函数在scipy.special
import scipy.special as ssss.beta(x1, x2)
相关分布(概率密度)在scipy.stats
import scipy.stats as stss.beta(a, b) # 随机变量
β Function:
主要性质:
Γ function
其递归形式如下:
关系
scipy中的相关实现
>>> from scipy.special import beta>>> from scipy.special import gamma>>> beta(6, 7) == gamma(6)*gamma(7)/gamma(6+7)True
Beta distribution 及其与Beta function and Gamma function的关系
Beta分布的概率密度函数(pdf)为:
>>> st.beta(2, 2).pdf(.5) == .5*.5/ss.beta(2, 2)True
beta distribution是一种在[0, 1]区间上的连续分布,在[0, 1]区间内概率密度值可以为
import numpy as npimport scipy.special as ssfrom scipy import integrateimport matplotlib.pyplot as pltdef beta(x, a, b): return x**(a-1)*(1-x)**(b-1)/ss.beta(a, b)def show_pdf(): x = np.arange(0, 1, .01) for (a, b) in [(.5, .5), (5, 1), (1, 3), (2, 2), (2, 5)]: plt.plot(x, beta_pdf(x, a, b), label='a={:.1f}, b={:.1f}'.format(a, b), lw=2) plt.legend(loc='upper center', frameon=False) plt.ylim([0, 3.5]) plt.ylabel('pdf') plt.savefig('./imgs/pdf.png') plt.show()def show_cdf(): x = np.arange(0+0.0001, 1, .0001) for (a, b) in [(.5, .5), (5, 1), (1, 3), (2, 2), (2, 5)]: plt.plot(x, [(integrate.quad(beta_pdf, 0, x, args=(a, b)))[0] for x in x], label='a={:.1f}, b={:.1f}'.format(a, b), lw=2) plt.legend(loc='upper left', frameon=False) plt.ylabel('cdf') plt.savefig('./imgs/cdf.png') plt.show()if __name__ == '__main__': show_pdf() show_cdf()
Beta分布的峰值在
先验为 Beta 分布,似然为二项分布时的后验分布
import numpy as npimport scipy.stats as stimport matplotlib.pyplot as pltn, k = 100, 61p = k/nrv = st.binom(n, p)a, b = 10, 10prior = st.beta(a, b)poster = st.beta(a+k, b+n-k)thetas = np.arange(0, 1, .001)plt.figure(figsize=(12, 9))plt.style.use('ggplot')plt.plot(thetas, prior.pdf(thetas), 'b', label='Prior')plt.plot(thetas, n*st.binom(n, thetas).pmf(k), 'g', label='Likelihood')plt.plot(thetas, poster.pdf(thetas), 'r', label='Poster')plt.axvline(p, c='g', ls='--', label='MLE', alpha=.4)plt.axvline((a+k-1)/(a+b+n-2), c='r', ls='--', label='MAP', alpha=.4)plt.legend(frameon=False)plt.xlabel(r'$\theta$', fontsize=14)plt.ylabel('Density', fontsize=16)plt.show()
0 0
- Beta函数与Gamma函数及其与Beta分布的关系
- Beta函数与Gamma函数及其与Beta分布的关系
- 暴力推导 Beta 函数与 Gamma 函数关系式
- Gamma函数 & Beta分布 & Dirichlet分布 & Symmetric Dirichlet
- Gamma/Beta 分布
- 二项分布与beta分布
- Beta分布与Dirichilet分布
- 关于Beta分布、二项分布与Dirichlet分布、多项分布的关系
- 关于Beta分布、二项分布与Dirichlet分布、多项分布的关系
- 关于Beta分布、二项分布与Dirichlet分布、多项分布的关系
- 关于Beta分布、二项分布与Dirichlet分布、多项分布的关系
- Beta分布及其应用
- Gamma 函数与exponential power distribution (指数幂分布)
- 概率分布之Beta分布与Dirichlet分布
- 【联系】—— Beta 分布与二项分布、共轭分布
- 关于共轭分布,beta分布,二项分布和Dirichlet分布、多项式分布的关系
- Gamma 函数及其应用
- beta分布
- Logitech的SetPointP控制网易云音乐,千千静听
- HDU 2138 How many prime numbers
- 逆向工程
- Appium的一点一滴:Mobile JSON Wire Protocol
- ActiveMQ实现负载均衡+高可用部署方案【未完待续】
- Beta函数与Gamma函数及其与Beta分布的关系
- URL编解码
- 浦发银行微信支付/绑定状态异常,请解绑后重新绑定
- QT学习之路(2):基础学习(1)
- HDOJ 2124 Repair the Wall
- PHP时区设置
- It seems that this file has not been built yet.Do you want to build it now? Codeblocks能构建build不能运run
- Python程序无法在命令行下运行
- installsheild2011打包程序internal build error 6213