Skip to content

Commit

Permalink
option to use more parallelization in profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
msuchard committed Oct 24, 2024
1 parent 57f0b61 commit f0e92b5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ Suggests:
microbenchmark,
cmprsk
NeedsCompilation: yes
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
17 changes: 13 additions & 4 deletions R/ModelFit.R
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ confint.cyclopsFit <- function(object, parm, level = 0.95, #control,
#' @param maxResets Maximum allowed number of recomputing the likelihood when coefficient drift is
#' detected.
#' @param includePenalty Logical: Include regularized covariate penalty in profile
#' @param optimalWarmStart Logical: Use optimal warm-starting when parallelizing evaluations
#'
#' @return
#' A data frame containing the profile log likelihood. Returns NULL when the adaptive profiling fails
Expand All @@ -918,7 +919,8 @@ getCyclopsProfileLogLikelihood <- function(object,
tolerance = 1E-3,
initialGridSize = 10,
maxResets = 10,
includePenalty = TRUE) {
includePenalty = TRUE,
optimalWarmStart = TRUE) {

if (!xor(is.null(x), is.null(bounds))) {
stop("Must provide either `x` or `bounds`, but not both.")
Expand All @@ -938,7 +940,8 @@ getCyclopsProfileLogLikelihood <- function(object,
priorMaxMaxError <- Inf
resetsPerformed <- 0
while (length(grid) != 0) {
ll <- fixedGridProfileLogLikelihood(object, parm, grid, includePenalty)
ll <- fixedGridProfileLogLikelihood(object, parm, grid, includePenalty,
optimalWarmStart)
profile <- bind_rows(profile, ll) %>% arrange(.data$point)
invalid <- is.nan(profile$value) | is.infinite(profile$value)
if (any(invalid)) {
Expand Down Expand Up @@ -1002,19 +1005,25 @@ getCyclopsProfileLogLikelihood <- function(object,
grid <- (profile$point[exceed] + profile$point[exceed + 1]) / 2
}
} else { # Use x
profile <- fixedGridProfileLogLikelihood(object, parm, x, includePenalty)
profile <- fixedGridProfileLogLikelihood(object, parm, x, includePenalty,
optimalWarmStart)
}

return(profile)
}

fixedGridProfileLogLikelihood <- function(object, parm, x, includePenalty) {
fixedGridProfileLogLikelihood <- function(object, parm, x, includePenalty,
optimalWarmStart = TRUE) {

.checkInterface(object$cyclopsData, testOnly = TRUE)
parm <- .checkCovariates(object$cyclopsData, parm)
threads <- object$threads

if (getNumberOfCovariates(object$cyclopsData) == 1 || length(x) == 1) {
grid <- .cyclopsGetProfileLikelihood(object$cyclopsData$cyclopsInterfacePtr, parm, x,
threads, includePenalty)
} else if (!optimalWarmStart && length(x) / 2 >= threads) {

grid <- .cyclopsGetProfileLikelihood(object$cyclopsData$cyclopsInterfacePtr, parm, x,
threads, includePenalty)
} else {
Expand Down
5 changes: 4 additions & 1 deletion man/getCyclopsProfileLogLikelihood.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f0e92b5

Please sign in to comment.