问题描述
我对 PyStan 越来越熟悉了。我已经运行了几个模型,包括贝叶斯线性回归模型,没有问题。但是,当我尝试运行以下代码时,出现段错误错误:
Segmentation fault (core dumped)
有趣的是,这只发生在老化迭代完成之后。我的模型代码在这里。我目前正在编造一些数据并尝试推断参数 beta_tru_1
和 alpha
。模型代码来自 Stan User's Guide。
import pystan
import numpy as np
from scipy.stats import norm
# the params
beta_tru_1 = 3.7
alpha = 2.3
# make some data
n = 1000
np.random.seed(1)
x1 = norm(0,1).rvs(n)
z = alpha + x1 * beta_tru_1
y = [1 if i > 0.7 else 0 for i in norm.cdf(z)]
# train test split
y_train,y_test = y[:750],y[750:]
x_train,x_test = x1[:750],x1[750:]
# stan code
probit_code = """
data {
int<lower=0> n; // number of data vectors
real x[n]; // data matrix
int<lower=0,upper=1> y[n]; // response vector
}
parameters {
real beta; // regression coefs
real alpha;
}
model {
for (i in 1:n)
y[i] ~ bernoulli(Phi(alpha + beta * x[i]));
}
"""
# compile the model
probit_model = pystan.StanModel(model_code=probit_code)
# the data
probit_dat = {
"n": len(y_train),"y": y_train,"x": x_train
}
# fit the model (small number of iterations for debug)
# this is where the error is
probit_fit = probit_model.sampling(data=probit_dat,iter=500,warmup=500,chains=4,init="0")
我在 Linux Pop OS 20.10 上使用 PyStan v. 2.19.1.1 和 python 3.7.6。我已经在多台机器上运行了这段代码,包括一个 Ubuntu 容器,但没有运气。任何帮助表示赞赏。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)