Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recording and reporting of method execution time #15

Merged
merged 4 commits into from
Apr 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions R/Method.R
Original file line number Diff line number Diff line change
Expand Up @@ -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) },
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion R/StepOne.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions R/StepThree.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion R/StepTwo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()

Expand All @@ -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"))
}
),

Expand All @@ -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) }
)
)

Expand Down
2 changes: 1 addition & 1 deletion R/Validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "")
Expand Down
4 changes: 2 additions & 2 deletions R/exports.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "")
Expand Down Expand Up @@ -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 = "")
Expand Down
2 changes: 1 addition & 1 deletion man-roxygen/powerly.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion man/powerly.Rd

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