Skip to content

Commit

Permalink
add memory usage recoding & figs
Browse files Browse the repository at this point in the history
  • Loading branch information
HelenaLC committed Jan 24, 2022
1 parent 0a9f918 commit eb9242c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]),
Expand Down
9 changes: 9 additions & 0 deletions code/07-plot_memory.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))])

Expand Down
16 changes: 12 additions & 4 deletions code/07-plot_runtimes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(),
Expand Down
59 changes: 59 additions & 0 deletions code/08-fig_scalability.R
Original file line number Diff line number Diff line change
@@ -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")

0 comments on commit eb9242c

Please sign in to comment.