浩晨众云网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
PyStan 为 Stan 提供了一个 Python 接口,这是一个使用 No-U-Turn 采样器进行贝叶斯推理的软件包,这是Hamiltonian Monte Carlo 的一种变体。
PyStan具有以下依赖项:
Python:2.7,> = 3.3
Cython:> = 0.22
NumPy:> = 1.7
PyStan还要求在安装和运行时可以使用C ++编译器。 在基于Debian的系统上,这是通过发出命令apt-get install build-essential来完成的。
例子:
import pystan schools_code = """ data { intJ; // number of schools vector[J] y; // estimated treatment effects vector [J] sigma; // s.e. of effect estimates } parameters { real mu; real tau; vector[J] eta; } transformed parameters { vector[J] theta; theta = mu + tau * eta; } model { eta ~ normal(0, 1); y ~ normal(theta, sigma); } """schools_dat = {'J': 8, 'y': [28, 8, -3, 7, -1, 1, 18, 12], 'sigma': [15, 10, 16, 11, 9, 11, 10, 18]} sm = pystan.StanModel(model_code=schools_code) fit = sm.sampling(data=schools_dat, iter=1000, chains=4)
需要资料,看个简介
素材来源中:开源中国