当尝试适合简单模型时,我在控制台中收到此错误消息:
Chain 3, Iteration: 800 / 2000 [ 40%] (Warmup)
Chain 2, Iteration: 800 / 2000 [ 40%] (Warmup)
Chain 3, Iteration: 1000 / 2000 [ 50%] (Warmup)python(9919,0x700001b19000) malloc: *** error for object 0x10b7c86e0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Chain 2, Iteration: 1000 / 2000 [ 50%] (Warmup)python(9918,0x700001b19000) malloc: *** error for object 0x10b7c86e0: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
尝试用conda和/或pip安装pystan。
Python 3.5
OS X El capitan 10.11.4
尝试过Pystan 2.8.0.0和2.9.0.0
这是一个完整的代码,从Jupyter
复制粘贴import numpy as np
import pystan
true_a = 5.6
true_b = 0.17
true_sigma = 3.0
np.random.seed(1)
x = np.random.uniform(0, 100, 200)
y = true_a + true_b*x + np.random.normal(0, true_sigma, len(x))
stan_datadict = {}
stan_datadict['N'] = len(x)
stan_datadict['x'] = x
stan_datadict['y'] = y
stan_ols = """
data {
int<lower=0> N; // count of observations
vector[N] x; // exog features
vector[N] y; // endog feature
}
parameters {
real alpha; // intercept (default uniform [-inf, inf])
real beta; // slope (default uniform [-inf, inf])
real<lower=0> sigma; // model error (default uniform [0, inf])
}
model {
y ~ normal(alpha + beta * x, sigma); // normal likelihood
}
"""
stan_fit_ols = pystan.stan(model_code=stan_ols, data=stan_datadict,
iter=2000, warmup=1000, chains=4, n_jobs=2,verbose=False)