Some rough benchmarks for testing how long things take...
library(tidyverse) library(tidybayes)
spread/gather_draws
k = 50000 set.seed(1234) df = data.frame( .chain = NA, .iteration = NA, .draw = 1:k, `a[2]` = rnorm(k), `b[2]` = rnorm(k), `c[2]` = rnorm(k), `d[2]` = rnorm(k), `e[2]` = rnorm(k), `f[2]` = rnorm(k), `g[2]` = rnorm(k), `h[2]` = rnorm(k), `i[2]` = rnorm(k), `j[2]` = rnorm(k), `k[2]` = rnorm(k), `l[2]` = rnorm(k), stringsAsFactors = FALSE, check.names = FALSE ) %>% as_tibble() df
This should be fairly fast. Last test was ~= 0.03 seconds on monarch
.
system.time(spread_draws(df, `.`[index], regex = TRUE))
This is definitely slower than it could be, likely due to use of joins with chain information involved. This could almost
definitely be made faster if nesting was used all the way up the spread_draws pipeline and chain information added
at the last possible moment. Last test was ~= 0.35 seconds on monarch
.
system.time(spread_draws(df, a[index], b[index], c[index], d[index], e[index], f[index], g[index], h[index], i[index], j[index], k[index], l[index] ))
This is slower than the spread_draws version even though it shouldn't really have to be. This is a result of spread_draws_long_ doing a spread that is later undone by gather_draws. Could either use a flag to skip this (although that is a little complicated as the |
syntax might need the spread anyway) or rely on switching to nesting throughout the entire pipeline to just make the spread/gather round trip not so costly. Last test was ~= 0.13 seconds on monarch
.
system.time(gather_draws(df, `.`[index], regex = TRUE))
k = 2500 l = 40 nuisance = 9000 - l set.seed(1234) ldf = tibble( .chain = NA, .iteration = NA, .draw = 1:k ) for (i in 1:l) { ldf[[paste0("a[", i, "]")]] = rnorm(k) ldf[[paste0("b[", i, "]")]] = rnorm(k) } for (i in 1:nuisance) { ldf[[paste0("p", i)]] = rnorm(k) } head(ldf[,1:10])
lmcmc = coda::mcmc.list( coda::mcmc(select(ldf, -.chain, -.iteration, -.draw)), coda::mcmc(select(ldf, -.chain, -.iteration, -.draw)) )
Faster than it used to be, but still slow. Last test was ~.77 on monarch.
system.time(tidy_draws(lmcmc))
Last test was ~.95 on monarch
system.time(spread_draws(lmcmc, a[i], b[i]))
Note how a lot of the slowdown here is due to tidy_draws. Last test was ~.08 on monarch.
system.time(spread_draws(ldf, a[i], b[i]))
This tends to be slower than spreading without array columns. Last test was ~0.08 seconds on monarch
.
data(RankCorr, package = "ggdist") system.time(spread_draws(RankCorr, b[.,.]))
And this is currently very slow. Last test was ~0.55 seconds on monarch
.
system.time(spread_draws(df, a[.]))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.