资源简介
Python贝叶斯分析作为贝叶斯理论上的重要使用规则,该文件是这本书中对应的代码
代码片段和文件信息
from __future__ import division
import numpy as np
import scipy.stats.kde as kde
def hpd_grid(sample alpha=0.05 roundto=2):
“““Calculate highest posterior density (HPD) of array for given alpha.
The HPD is the minimum width Bayesian credible interval (BCI).
The function works for multimodal distributions returning more than one mode
Parameters
----------
sample : Numpy array or python list
An array containing MCMC samples
alpha : float
Desired probability of type I error (defaults to 0.05)
roundto: integer
Number of digits after the decimal point for the results
Returns
----------
hpd: array with the lower
“““
sample = np.asarray(sample)
sample = sample[~np.isnan(sample)]
# get upper and lower bounds
l = np.min(sample)
u = np.max(sample)
density = kde.gaussian_kde(sample)
x = np.linspace(l u 2000)
y = density.evaluate(x)
#y = density.evaluate(x l u) waitting for PR to be accepted
xy_zipped = zip(x y/np.sum(y))
xy = sorted(xy_zipped key=lambda x: x[1] reverse=True)
xy_cum_sum = 0
hdv = []
for val in xy:
xy_cum_sum += val[1]
hdv.append(val[0])
if xy_cum_sum >= (1-alpha):
break
hdv.sort()
diff = (u-l)/20 # differences of 5%
hpd = []
hpd.append(round(min(hdv) roundto))
for i in range(1 len(hdv)):
if hdv[i]-hdv[i-1] >= diff:
hpd.append(round(hdv[i-1] roundto))
hpd.append(round(hdv[i] roundto))
hpd.append(round(max(hdv) roundto))
ite = iter(hpd)
hpd = list(zip(ite ite))
modes = []
for value in hpd:
x_hpd = x[(x > value[0]) & (x < value[1])]
y_hpd = y[(x > value[0]) & (x < value[1])]
modes.append(round(x_hpd[np.argmax(y_hpd)] roundto))
return hpd x y modes
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 1\
文件 295868 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 1\01_Thinking_Probabilistically_a_Bayesian_Inference_Primer (3).ipynb
文件 1886 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 1\hpd (1).py
文件 23400 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 1\mauna_loa_CO2 (1).csv
文件 3670 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 1\plot_post (1).py
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 2\
文件 475295 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 2\02_Programming_probabilistically_a_PyMC3_primer (1).ipynb
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 3\
文件 1098467 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 3\03_Juggling with multiparametric and Hierarchical models.ipynb
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 4\
文件 2722708 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 4\04_Understanding_and_predicting_data_with_linear_regression_models (2).ipynb
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 5\
文件 1130805 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 5\05_Classifying_outcomes_with_logistic_regression (2).ipynb
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 6\
文件 597576 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 6\06_Model_comparison.ipynb
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 7\
文件 764114 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 7\07_Mixture_Models (1).ipynb
目录 0 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 8\
文件 829985 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\Chapter 8\08_Gaussian_processes.ipynb
文件 1062 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\LICENSE
文件 1595 2017-12-19 11:16 Bayesian-Analysis-with-Python-master\README.md
相关资源
-
lxm
l-4.3.3-cp38-cp38m-win_amd64.whl - python3.7.1rc1参考文档chm格式
- 用python写网络爬虫 PDF版
- Python编程:从入门到实践带书签完整
- Python从入门到精通134173
- Python基础教程第三版-中文完整文字版
- 雨痕的<>高清完整版
- Learning IPython for Interactive Computing and
- Flask Web开发:基于Python的Web应用开发
- python3 大华IP摄像头使用 SDK DLL 添加动
- 利用 Python 进行数据分析 第二版 中文
- TMDB500电影数据分析
- pygame.whl -1.9.3-cp37-cp37m-win_amd64+win32两个
-
Python_The Bible_3 Manusc
ripts in 1 book-Ma - Mastering Python Design Patterns精通Python设计
- Learning OpenCV 3 Computer Vision with Python
- python opengl编程
- 生物信息python中文版.pdf
- GTK+、glade学习C、Python实现
- 3ds Max Python API
- 算法与数据结构python版北大内部教材
- dlib-19.19.0-cp38-cp38-win_amd64.zip
- 项目实战 Python Django 个人网站 电影推
- python推箱子游戏
- Python语言程序设计2018版电子教案
- Practical Quantum Computing for Developers
- 【Python 知识图谱】(高清、超详细)
- 基于django的一个博客的前后端基础设
- python贪吃蛇进阶版完整代码
- 图像处理的详细python程序
评论
共有 条评论