RStan坚持'哈希不匹配所以重新编译'确保Stan代码以空行结束

时间:2018-04-24 13:07:18

标签: r rstan

我按照说明https://github.com/stan-dev/rstan/wiki/RStan-Getting-Started制作了rtools 3.4和rstan 2.17.3。

我保存了以下文件'8schools.stan':

data {
  int<lower=0> J; // number of schools 
  real y[J]; // estimated treatment effects
  real<lower=0> sigma[J]; // s.e. of effect estimates 
}
parameters {
  real mu; 
  real<lower=0> tau;
  real eta[J];
}
transformed parameters {
  real theta[J];
  for (j in 1:J)
    theta[j] = mu + tau * eta[j];
}
model {
  target += normal_lpdf(eta | 0, 1);
  target += normal_lpdf(y | theta, sigma);
}

但是当我打电话给代码时:

library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())

schools_dat <- list(J = 8, 
                    y = c(28,  8, -3,  7, -1,  1, 18, 12),
                    sigma = c(15, 10, 16, 11,  9, 11, 10, 18))
fit <- stan(file = '8schools.stan', data = schools_dat, 
            iter = 3, chains = 4)

我收到此错误:

hash mismatch so recompiling; make sure Stan code ends with a blank line
In file included from C:/Users/ubashir/Documents/R/win-library/3.4/BH/include/boost/config.hpp:39:0,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/BH/include/boost/math/tools/config.hpp:13,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core/var.hpp:7,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core/gevv_vvv_vari.hpp:5,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/core.hpp:12,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math/rev/mat.hpp:4,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/stan/math.hpp:4,
                 from C:/Users/ubashir/Documents/R/win-library/3.4/StanHeaders/include/src/stan/model/model_header.hpp:4,
                 from file1b0858a92ea1.cpp:8:
C:/Users/ubashir/Documents/R/win-library/3.4/BH/include/boost/config/compiler/gcc.hpp:186:0: warning: "BOOST_NO_CXX11_RVALUE_REFERENCES" redefined
 #  define BOOST_NO_CXX11_RVALUE_REFERENCES
 ^
<command-line>:0:0: note: this is the location of the previous definition
Error in checkForRemoteErrors(val) : 
  4 nodes produced errors; first error: unable to load shared object 'C:/Users/ubashir/AppData/Local/Temp/RtmpgJlrXy/file163456d0a16.dll':
  LoadLibrary failure:  Access is denied.

请帮助!

===================更新=========================== ==================

所以我按照Rtools 3.5和rstan(通过install.packages())重新安装R版本3.5.1

现在rstan失败了,如此支持多核支持:

library(rstan)
rstan_options(auto_write = TRUE)
options(mc.cores = 8)
fit <- stan(file = '8schools.stan', data = schools_dat, 
            iter = 3, chains = 4)

有错误:

Loading required namespace: rstudioapi
Error in checkForRemoteErrors(val) : 
  4 nodes produced errors; first error: unable to load shared object 'C:/Users/ubashir/AppData/Local/Temp/RtmpAtefGs/file241c40952587.dll':
  LoadLibrary failure:  Access is denied.

但是,如果我将线路更改为单核心,我可以让代码至少工作

1 个答案:

答案 0 :(得分:0)

只需在'8schools.stan'

的末尾添加换行符即可