-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfor_sam.R
42 lines (35 loc) · 846 Bytes
/
for_sam.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
library(cmdstanr)
source("generate_data.R")
data_list <- readRDS("data_list.RDS")
cores <- 4
nchains <- 1
thr_per_chain <- 4
# Compile non-parallel
mod <- cmdstan_model("models/wtf.stan")
fit <- mod$sample(
data = data_list,
iter_warmup = 0,
iter_sampling = 1,
chains = 1,
threads_per_chain = thr_per_chain,
init = initfn,
parallel_chains = 1,
fixed_param = TRUE
)
# Works...
fit$draws("log_lik", format = "matrix")
# Compile parallel
modp <- cmdstan_model("models/wtf.stan", force_recompile = TRUE,
cpp_options = list(stan_threads = TRUE))
fitp <- modp$sample(
data = data_list,
iter_warmup = 0,
iter_sampling = 1,
chains = 1,
threads_per_chain = thr_per_chain,
init = initfn,
parallel_chains = 1,
fixed_param = TRUE
)
# Doesn't work...
fitp$draws("log_lik", format = "matrix")