Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use draws from pathfinder posterior as inits #1662

Open
StaffanBetner opened this issue May 27, 2024 · 1 comment
Open

Use draws from pathfinder posterior as inits #1662

StaffanBetner opened this issue May 27, 2024 · 1 comment
Labels

Comments

@StaffanBetner
Copy link

The latest cmdstanr supports using (random draws from) a previous fit as inits. This is especially useful when using pathfinder to initialize HMC. It would be useful to have it in brms as well, either by providing a previous stanfit object or by specifying "pathfinder" as the init argument.

@StaffanBetner
Copy link
Author

StaffanBetner commented May 27, 2024

A simple workaround:

brm_pathfinder_inits <- function(...){
  brm(empty = T, ...) -> 
    brm_empty
  
  cmdstanr::write_stan_file(brm_empty$model) %>% 
    cmdstan_model(cpp_options = list(stan_threads = TRUE)) -> 
    model_cmdstan
  
  model_cmdstan$pathfinder(data = make_standata(...), 
                           init = 2, 
                           history_size = 100, 
                           num_threads = list(...)$cores, 
                           num_paths = list(...)$chains) ->
    pathfinder_inits
  
  
  brm(init = pathfinder_inits, ...) ->
    output_pathfinder_inits
  
  return(output_pathfinder_inits)
}

EDIT: Updated the code a little bit, and the instability seems to be fixed by stan-dev/cmdstanr#993

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants