【问题标题】:recompiling to avoid crashing R session重新编译以避免崩溃 R 会话
【发布时间】:2019-01-15 09:23:23
【问题描述】:

如何避免重新编译?

我的 stan() 正在重新编译以避免 R 会话崩溃。

为了验证我的模型,我想为来自已知分布的许多数据复制各种模型。但是rstan::stan() 总是重新编译我的 stan 文件,所以花了很长时间。如何避免重新编译。

编辑评论-------------

rstan::stan() 转换为rstan::sampling() 的备忘录。

rstan::stan中,它的变量名是model_name

 m <- "foo.stan"
 rstan::stan( model_name =m, data =...)

另一方面,在rstan::sampling 中,它的变量名是object

   m <- "foo.stan"
   m <- stan_model(m)
   rstan::sampling( object = m , data = ...)

请小心!!变量名不一样!!

【问题讨论】:

    标签: stan rstan


    【解决方案1】:

    使用函数stan_model进行编译,然后在sampling函数中使用编译后的模型输出。例如:

    m <- stan_model('foo.stan')
    fit <- sampling(m, data = ...)
    

    而不是

    fit <- stan('foo.stan', data = ...)
    

    【讨论】:

    • 是的,第一个 model_name 采用包含程序文本的文件的路径。第二个,stan_model,采用编译模型,就像你从 stan_model() 获得的模型一样。
    • 我试过了,但是出现上述错误。这个错误是什么意思?
    • 对于rstan::sampling 调用,您希望将stan_model() 生成的编译模型传递给它。
    猜你喜欢
    • 2014-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-15
    • 2012-05-08
    相关资源
    最近更新 更多