Cmdstan的Python接口
cmdstanp的Python项目详细描述
Cmdstanpy
对于python用户来说,cmdstanpy是stan的一个轻量级接口, 提供编译stan程序所需的对象和函数 运行斯坦的采样器。
目标
清理到stan服务的接口,以便cmdstanpy能够跟上stan版本。
提供完整的控件-所有采样器参数都具有相应的命名参数 用于CMDStanpy采样器函数。
易于安装,
- 最小的python库依赖项:numpy、pandas
- python代码不直接与c++接口,只调用编译的可执行文件
模块化-Cmdstanpy从后面的模块产生一个样本,下游的模块进行分析。
文件
见https://cmdstanpy.readthedocs.io/en/latest/index.html
源库
Cmdstan的源代码存储库托管在Github上。
许可
CMdStPyPy、CmdStan和核心Stan C++代码在新的BSD下得到许可。
示例
::
import os
from cmdstanpy import Model, StanFit, cmdstan_path
# specify Stan file, create, compile Model object
bernoulli_path = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan')
bernoulli_model = Model(stan_file=bernoulli_path)
bernoulli_model.compile()
# specify data, fit the model
bernoulli_data = { "N" : 10, "y" : [0,1,0,0,0,0,0,0,0,1] }
bernoulli_fit = bernoulli_model.sample(chains=5, cores=3, data=bernoulli_data)
# summarize the results (wraps CmdStan `bin/stansummary`):
bernoulli_fit.summary()