Skip to content

Instantly share code, notes, and snippets.

@StaffanBetner
Last active June 11, 2024 11:15
Show Gist options
  • Save StaffanBetner/4e451a6cd547e655ed1ed19dd2db5542 to your computer and use it in GitHub Desktop.
Save StaffanBetner/4e451a6cd547e655ed1ed19dd2db5542 to your computer and use it in GitHub Desktop.
library(cmdstanr)
library(brms)
brm_pathfinder_inits <- function(..., psis_resample=TRUE, max_lbfgs_iters = 2500, history_size = 100){
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 = history_size,
max_lbfgs_iters = max_lbfgs_iters,
num_threads = list(...)$cores, psis_resample=psis_resample,
num_paths = list(...)$chains) ->
pathfinder_inits
brm(init = pathfinder_inits, ...) ->
output_pathfinder_inits
return(output_pathfinder_inits)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment