diff --git a/Snakefile b/Snakefile index 27c2f23..c24daba 100755 --- a/Snakefile +++ b/Snakefile @@ -818,6 +818,10 @@ plts = { "memory": expand( "plts/mbs_{reftyp}.rds", reftyp = REFTYPS), + "scalability": expand( + "plts/{which}_{reftyp}.rds", + which = ["rts", "mbs"], + reftyp = REFTYPS), "scatters": expand( "plts/stat_{dim}d-scatters.rds", dim = ["1", "2"]), diff --git a/code/07-plot_memory.R b/code/07-plot_memory.R index bf743c1..c851725 100755 --- a/code/07-plot_memory.R +++ b/code/07-plot_memory.R @@ -36,11 +36,20 @@ df <- data.frame(mbs, reftyp, refset, vars) %>% group_by(method, dim, n) %>% summarise_at("mbs", mean) +# order methods by average across subsets +ms <- df %>% + group_by(method) %>% + summarise_at("mbs", mean) %>% + arrange(mbs) %>% pull("method") +df$method <- factor(df$method, levels = ms) + pal <- .methods_pal[levels(df$method)] + lab <- parse(text = paste( sep = "~", sprintf("bold(%s)", LETTERS), gsub("\\s", "~", names(pal)))) + anno <- mutate(df, letter = LETTERS[ match(method, levels(method))]) diff --git a/code/07-plot_runtimes.R b/code/07-plot_runtimes.R index 9190bd1..9ddb237 100755 --- a/code/07-plot_runtimes.R +++ b/code/07-plot_runtimes.R @@ -46,6 +46,14 @@ df <- res %>% group_by(method, step, dim, n) %>% summarise_at("t", mean) +# order methods by overall average across subsets +ms <- df %>% + filter(step == "overall") %>% + group_by(method) %>% + summarise_at("t", mean) %>% + arrange(t) %>% pull("method") +df$method <- factor(df$method, levels = ms) + pal <- .methods_pal[levels(df$method)] lab <- parse(text = paste( @@ -65,13 +73,13 @@ plt <- ggplot(df, aes(factor(n), t, stat = "identity", position = "dodge") + geom_text(data = anno, - aes(label = letter, y = 0.1), - size = 1.5, color = "black", + aes(label = letter, y = 0), + size = 1.5, vjust = 2, color = "black", position = position_dodge(0.9)) + scale_fill_manual(values = pal, labels = lab) + scale_color_manual(values = pal, labels = lab) + - xlab(NULL) + scale_y_log10("runtime (s)", - expand = expansion(mult = 0.1)) + xlab(NULL) + scale_y_sqrt("runtime (s)", + expand = expansion(mult = c(0.2, 0.1))) thm <- theme( axis.ticks.x = element_blank(), diff --git a/code/08-fig_scalability.R b/code/08-fig_scalability.R new file mode 100755 index 0000000..e7e0cc8 --- /dev/null +++ b/code/08-fig_scalability.R @@ -0,0 +1,59 @@ +# args <- list( +# rds = list.files("plts", "(rts|mbs).*\\.rds", full.names = TRUE), +# pdf = "figs/rts_vs_mbs.pdf", +# uts = "code/utils-plotting.R") + +source(args$uts) +ps <- lapply(args$rds, readRDS) + +pat <- ".*_([a-z])\\.rds" +reftyp <- gsub(pat, "\\1", basename(args$rds)) +is <- split(seq_along(ps), reftyp)[c("n", "b", "k")] + +ps <- lapply(is, \(i) { + + nm <- c("rts", "mbs") + for (j in seq_along(nm)) { + k <- grep(nm[[j]], args$rds[i]) + df <- paste0("df_", nm[[j]]) + assign(df, ps[i][[k]]$data) + } + + i <- c("method", "dim", "n", j <- c("t", "mbs")) + #f <- \(.) factor(., sort(as.numeric(as.character(unique(.))))) + f <- \(.) as.numeric(as.character(.)) + df_rts <- df_rts %>% + filter(step == "overall") %>% + mutate(n = f(n)) %>% ungroup() %>% select(any_of(i)) + + df_mbs <- df_mbs %>% + mutate(n = f(n)) %>% ungroup() %>% select(any_of(i)) + + df <- full_join( + df_rts, df_mbs, + by = setdiff(i, j)) %>% + filter(!is.na(t), !is.na(mbs)) + pal <- .methods_pal[levels(df$method)] + + p <- ggplot(df, aes(t, mbs, col = method, fill = method)) + + scale_color_manual(values = pal) + + scale_fill_manual(values = pal) + + facet_grid(~ dim) + + geom_point(alpha = 0.8) + + geom_path(size = 0.2) + + scale_x_continuous("runtime (s)", limits = c(0, NA), trans = "sqrt") + + scale_y_continuous("memory usage (MBs)", limits = c(0, NA)) + + .prettify(p) + theme( + panel.grid.major = element_line(color = "grey", size = 0.2)) +}) + +fig <- wrap_plots(ps, ncol = 1) + + plot_annotation(tag_levels = "a") & + theme( + plot.margin = margin(), + panel.spacing = unit(1, "mm"), + legend.title = element_blank(), + plot.tag = element_text(size = 9, face = "bold")) + +ggsave(args$pdf, fig, width = 16, height = 16, units = "cm")