是否无法调试以下错误,或者是否存在任何对应的错误
browser()
的功能。
当函数sampling()
无法创建stanfit
对象时,我想在Stan文件中提取转换后的数据块的对象。
failed to create the sampler; sampling not done
Error in new_CppObject_xp(fields$.module, fields$.pointer, ...) :
Exception: binomial_rng: Probability parameter is nan, but must be in the interval [0, 1] (in 'model23b420c17ad_SBC' at line 247)
答复: Stan文件中的功能Print()
作为调试器:
使用print(),我们可以打印转换后的数据块中的任何对象,而不管函数rstan::sampling()
的结果如何。
m <- rstan::stan_model(model_code = '
data{real x;}
transformed data{real z; z = Phi( (-1.14194+ 2.66963)/(-0.257783) );
print("Here, we can use print() as a debugger")
print("")
print("z = ", z)
}
parameters {real y;}
model {y ~ normal(z,1);}
generated quantities {real zhat = z;}')
f <- rstan::sampling(m, data=list(x=1), iter = 100,chains=1)
extract(f)[["zhat"]]
作为上述玩具代码的结果,Stan文件中的指定对象在R控制台中的打印如下:
> f <- rstan::sampling(m, data=list(x=1), iter = 100,chains=1)
Here, we can use print() as a debugger
z = 1.54953e-009
SAMPLING FOR MODEL 'adff65652652045694506de44240c84c' NOW (CHAIN 1).
Chain 1:
Chain 1: Gradient evaluation took 0 seconds
Chain 1: 1000 transitions using 10 leapfrog steps per transition would take 0 seconds.
Chain 1: Adjust your expectations accordingly!
Chain 1:
Chain 1:
Chain 1: WARNING: There aren't enough warmup iterations to fit the
Chain 1: three stages of adaptation as currently configured.
Chain 1: Reducing each adaptation stage to 15%/75%/10% of
Chain 1: the given number of warmup iterations:
Chain 1: init_buffer = 7
Chain 1: adapt_window = 38
Chain 1: term_buffer = 5
Chain 1:
Chain 1: Iteration: 1 / 100 [ 1%] (Warmup)
Chain 1: Iteration: 10 / 100 [ 10%] (Warmup)
Chain 1: Iteration: 20 / 100 [ 20%] (Warmup)
Chain 1: Iteration: 30 / 100 [ 30%] (Warmup)
Chain 1: Iteration: 40 / 100 [ 40%] (Warmup)
Chain 1: Iteration: 50 / 100 [ 50%] (Warmup)
Chain 1: Iteration: 51 / 100 [ 51%] (Sampling)
Chain 1: Iteration: 60 / 100 [ 60%] (Sampling)