diff --git a/R/Method.R b/R/Method.R index f7ff84e..38bbd12 100644 --- a/R/Method.R +++ b/R/Method.R @@ -182,7 +182,11 @@ Method <- R6::R6Class("Method", active = list( # Time elapsed until converged. - duration = function() { return(private$.end_time - private$.start_time) }, + duration = function() { + return( + as.numeric(difftime(private$.end_time, private$.start_time, units = "secs")) + ) + }, # Number of iterations performed. iteration = function() { return(private$.iteration) }, @@ -208,7 +212,7 @@ Method <- R6::R6Class("Method", #' @template summary-Method #' @export summary.Method <- function(object, ...) { - cat("\n", "Method run completed (", as.numeric(round(object$duration, 4)), " sec):", sep = "") + cat("\n", "Method run completed (", round(object$duration, 4), " sec):", sep = "") cat("\n", " - converged: ", ifelse(object$converged, "yes", "no"), sep = "") cat("\n", " - iterations: ", object$iteration, sep = "") cat("\n", " - recommendation: ", paste(paste( diff --git a/R/StepOne.R b/R/StepOne.R index 7638a5c..aceaecc 100644 --- a/R/StepOne.R +++ b/R/StepOne.R @@ -178,7 +178,7 @@ StepOne <- R6::R6Class("StepOne", private$.remove_missing() # Compute how long the simulation took. - private$.duration <- Sys.time() - start_time + private$.duration <- as.numeric(difftime(Sys.time(), start_time, units = "secs")) }, # Compute the statistics for the Monte Carlo simulations. diff --git a/R/StepThree.R b/R/StepThree.R index ac50db2..65375e5 100644 --- a/R/StepThree.R +++ b/R/StepThree.R @@ -181,7 +181,7 @@ StepThree <- R6::R6Class("StepThree", } # Compute how long the bootstrap took. - private$.duration <- Sys.time() - start_time + private$.duration <- as.numeric(difftime(Sys.time(), start_time, units = "secs")) }, # Compute confidence intervals. @@ -206,7 +206,7 @@ StepThree <- R6::R6Class("StepThree", } # Compute how long the bootstrap took. - private$.duration <- Sys.time() - start_time + private$.duration <- private$.duration + as.numeric(difftime(Sys.time(), start_time, units = "secs")) # Extract the confidence intervals for the sufficient sample sizes. private$.extract_sufficient_samples(private$.step_2$step_1$statistic_value) diff --git a/R/StepTwo.R b/R/StepTwo.R index 468944e..a5e5228 100644 --- a/R/StepTwo.R +++ b/R/StepTwo.R @@ -7,6 +7,8 @@ StepTwo <- R6::R6Class("StepTwo", .interpolation = NULL, .cv = NULL, + .duration = NULL, + # Decide how many DF can be used during the LOOCV. .check_df = function(df, monotone) { # If we have an I-Spline then we can start 1 degree of freedom lower. @@ -136,6 +138,9 @@ StepTwo <- R6::R6Class("StepTwo", }, fit = function(monotone = TRUE, increasing = TRUE, df = NULL, solver_type = "quadprog", ...) { + # Time when the fitting started. + start_time <- Sys.time() + # Reset any previous spline before re-fitting. private$.clear_spline() @@ -147,6 +152,9 @@ StepTwo <- R6::R6Class("StepTwo", # Interpolate the entire range used during Step 1. private$.interpolate(...) + + # Compute how long the simulation took. + private$.duration <- as.numeric(difftime(Sys.time(), start_time, units = "secs")) } ), @@ -157,7 +165,8 @@ StepTwo <- R6::R6Class("StepTwo", cv = function() { return(private$.cv) }, ssq = function() { return(sum((private$.step_1$statistics - private$.spline$fitted) ^ 2)) - } + }, + duration = function() { return(private$.duration) } ) ) diff --git a/R/Validation.R b/R/Validation.R index fc0a75f..89b3886 100644 --- a/R/Validation.R +++ b/R/Validation.R @@ -96,7 +96,7 @@ Validation <- R6::R6Class("Validation", #' @template summary-Validation #' @export summary.Validation <- function(object, ...) { - cat("\n", "Validation completed (", as.numeric(round(object$validator$duration, 4)), " sec):", sep = "") + cat("\n", "Validation completed (", round(object$validator$duration, 4), " sec):", sep = "") cat("\n", " - sample: ", object$sample, sep = "") cat("\n", " - statistic: ", object$statistic, sep = "") cat("\n", " - measure at ", object$percentile, " pert.: ", round(object$percentile_value, 3), sep = "") diff --git a/R/exports.R b/R/exports.R index 99683e4..f87bb11 100644 --- a/R/exports.R +++ b/R/exports.R @@ -95,7 +95,7 @@ powerly <- function( # Inform the user about the method status. if (verbose) { - cat("\n", "Method run completed (", as.numeric(round(method$duration, 4)), " sec):", sep = "") + cat("\n", "Method run completed (", round(method$duration, 4), " sec):", sep = "") cat("\n", " - converged: ", ifelse(method$converged, "yes", "no"), sep = "") cat("\n", " - iterations: ", method$iteration, sep = "") cat("\n", " - recommendation: ", method$step_3$samples["50%"], "\n", sep = "") @@ -153,7 +153,7 @@ validate <- function( # Information regarding the results of the validation. if (verbose) { - cat("\n", "Validation completed (", as.numeric(round(validation$validator$duration, 4)), " sec):", sep = "") + cat("\n", "Validation completed (", round(validation$validator$duration, 4), " sec):", sep = "") cat("\n", " - sample: ", validation$sample, sep = "") cat("\n", " - statistic: ", validation$statistic, sep = "") cat("\n", " - measure at ", validation$percentile, " pert.: ", round(validation$percentile_value, 3), sep = "") diff --git a/man-roxygen/powerly.R b/man-roxygen/powerly.R index 9d74be3..16875f6 100644 --- a/man-roxygen/powerly.R +++ b/man-roxygen/powerly.R @@ -167,7 +167,7 @@ #' each step of the method for the last and previous iterations. #' #' Main fields: -#' - **`$duration`**: The time elapsed during the method run. +#' - **`$duration`**: The time in seconds elapsed during the method run. #' - **`$iteration`**: The number of iterations performed. #' - **`$converged`**: Whether the method converged. #' - **`$previous`**: The results during the previous iteration. diff --git a/man/powerly.Rd b/man/powerly.Rd index b850815..376ef6a 100644 --- a/man/powerly.Rd +++ b/man/powerly.Rd @@ -145,7 +145,7 @@ each step of the method for the last and previous iterations. Main fields: \itemize{ -\item \strong{\verb{$duration}}: The time elapsed during the method run. +\item \strong{\verb{$duration}}: The time in seconds elapsed during the method run. \item \strong{\verb{$iteration}}: The number of iterations performed. \item \strong{\verb{$converged}}: Whether the method converged. \item \strong{\verb{$previous}}: The results during the previous iteration.