Skip to content

Commit

Permalink
Refined path chunking, keeping 'degen' in bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
David Norris authored and David Norris committed Mar 23, 2021
1 parent b65702d commit 968ad6e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 5 additions & 4 deletions R/dtp.R
Original file line number Diff line number Diff line change
Expand Up @@ -218,17 +218,18 @@ calculate_dtps <- function (next_dose, cohort_sizes,
if (is.na(etcoh) || etcoh==length(dose_recs))
next
## Upon reaching this point, we have detected an early termination (ET).
degen <- prod(1 + cohort_sizes[-(1:etcoh)]) - 1
degen <- min(prod(1 + cohort_sizes[-(1:etcoh)]) - 1,
ncol(dtps) - i) # avoid overrunning bounds
dtps[,i + (1:degen)] <- dtps[,i]
i <- i + degen
skipped <- skipped + degen
}
dtps <- data.frame(t(dtps))
}
chunks <- if (mc.cores == 1)
chunks <- if (mc.cores == 1 || ncol(paths)<3)
list(paths) # singleton 'chunk'
else # TODO: Split on cols 3:1 or 4:1 in case of smaller (e.g., n=1) cohorts
split(paths, paths[,2:1], drop=TRUE) # note reversed order of factor columns
else # TODO: Split into about mc.cores^2 chunks
split(paths, paths[,3:1], drop=TRUE) # note reversed order of factor columns
dtps <- do.call("rbind",
parallel::mclapply(chunks, scan_dtps, mc.cores = mc.cores))
colnames(dtps) <- c("D0", as.vector(rbind(paste0("T", 1:num_cohorts),
Expand Down
16 changes: 16 additions & 0 deletions tests/manual/speed.R
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ viola_speedup_report <- function() {
## 2x would be anticipated) shows that the chunking (suppressed in case mc.cores=1)
## itself accomplishes a great deal. This suggests that my earlier 'rolling' while
## loop may have been the more efficient way to traverse the degeneracy, after all!
## ...
## More learning...
## A more efficient loop (with en bloc degeneracy skip) achieves this:
## pnorm skipt rusti core2 core4 core6 core8
## 107.239 59.965 21.064 13.445 10.223 8.081 7.945
##
## Now the improvement is 107/60 = 1.8x, and deeper thinking about the algorithm
## reveals why this should not be 3.5x. The more highly degenerate paths have
## fewer crm() calls, so the savings are not proportional to path degeneracy.
## ...
## Now splitting more finely (on first 3 columns) yields this:
## pnorm skipt rusti core2 core4 core6 core8
## 107.874 60.159 21.056 13.164 9.558 7.805 7.753
##
## Exactly as one might expect, the finer division helps squeeze extra value
## out of more cores.

## Calculate potential savings (%) in the cascade
## of function calls during VIOLA DTP
Expand Down

0 comments on commit 968ad6e

Please sign in to comment.