How to globally set iterations and chains in R brms? - Stack Overflow

I'm trying to set some global options for iterations and chains in brms to avoid specifying them e

I'm trying to set some global options for iterations and chains in brms to avoid specifying them explicitly in each model call, as I have a very long script with many models. According to the documentation, I tried setting the following options globally, but they don't work:

library(brms)

options(
  brms.iter = 100,          # Does not work
  mc.iter = 100,            # Does not work
  brms.chains = 1,          # Does not work
  mc.chains = 1,            # Does not work
  mc.cores = 4,             # Works, but confusing because it's not brms.cores
  brms.backend = 'cmdstanr' # Works
)

mdl <- brm(speed ~ dist, data = cars)

What's the correct way to globally control the number of iterations and chains?

I'm trying to set some global options for iterations and chains in brms to avoid specifying them explicitly in each model call, as I have a very long script with many models. According to the documentation, I tried setting the following options globally, but they don't work:

library(brms)

options(
  brms.iter = 100,          # Does not work
  mc.iter = 100,            # Does not work
  brms.chains = 1,          # Does not work
  mc.chains = 1,            # Does not work
  mc.cores = 4,             # Works, but confusing because it's not brms.cores
  brms.backend = 'cmdstanr' # Works
)

mdl <- brm(speed ~ dist, data = cars)

What's the correct way to globally control the number of iterations and chains?

Share Improve this question asked Mar 14 at 8:36 matmat 2,6395 gold badges37 silver badges79 bronze badges 3
  • discourse.mc-stan./t/… The answer to this question may be helpful – Coco Q. Commented Mar 14 at 9:03
  • 1 In brms, global options for iterations and chains can't be set via options(). Instead, specify them in each brm() call or use a custom wrapper function to apply defaults. – Szymon Roziewski Commented Mar 14 at 9:06
  • @SzymonRoziewski thanks. Can you post a response so I can validate it and close the thread? – mat Commented Mar 14 at 12:10
Add a comment  | 

1 Answer 1

Reset to default 1

In brms, there isn't a direct way to globally set the number of iterations and chains using R's global options. However, you can work around this limitation by defining default arguments with a custom wrapper function for your models.

brm_custom <- function(..., iter = 2000, chains = 4, cores = 1) {
  brm(..., iter = iter, chains = chains, cores = cores)
}

mdl <- brm_custom(speed ~ dist, data = cars)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744667345a4586831.html

相关推荐

  • How to globally set iterations and chains in R brms? - Stack Overflow

    I'm trying to set some global options for iterations and chains in brms to avoid specifying them e

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信