diff --git a/DESCRIPTION b/DESCRIPTION index 4e59523..08959d6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: probably Title: Tools for Post-Processing Predicted Values -Version: 1.1.1.9000 +Version: 1.1.1.9001 Authors@R: c( person("Max", "Kuhn", , "max@posit.co", role = c("aut", "cre")), person("Davis", "Vaughan", , "davis@posit.co", role = "aut"), diff --git a/NAMESPACE b/NAMESPACE index 23ed2dd..de28cd6 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -126,6 +126,10 @@ S3method(required_pkgs,cal_estimate_multinomial) S3method(required_pkgs,cal_estimate_multinomial_spline) S3method(required_pkgs,cal_estimate_none) S3method(required_pkgs,cal_object) +S3method(required_pkgs,int_conformal_cv) +S3method(required_pkgs,int_conformal_full) +S3method(required_pkgs,int_conformal_quantile) +S3method(required_pkgs,int_conformal_split) S3method(threshold_perf,data.frame) S3method(type_sum,cal_object) S3method(vec_cast,character.class_pred) diff --git a/NEWS.md b/NEWS.md index e788116..7be95a0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # probably (development version) +* Add `required_pkgs()` methods to `int_conformal_cv()`, `int_conformal_full()`, `int_conformal_quantile()`, and `int_conformal_split()`. (#190) + # probably 1.1.1 * Updated unit tests for new ggplot2 release (#180). diff --git a/R/conformal_infer.R b/R/conformal_infer.R index 10fadfa..6511193 100644 --- a/R/conformal_infer.R +++ b/R/conformal_infer.R @@ -113,6 +113,20 @@ print.int_conformal_full <- function(x, ...) { invisible(x) } +#' @rdname required_pkgs.int_conformal_cv +#' @keywords internal +#' @export +required_pkgs.int_conformal_full <- function(x, infra = TRUE, ...) { + model_pkgs <- required_pkgs(x$wflow, infra = infra) + + if (infra) { + model_pkgs <- c(model_pkgs, "probably") + } + + model_pkgs <- unique(model_pkgs) + model_pkgs +} + # ------------------------------------------------------------------------------ #' Prediction intervals from conformal methods diff --git a/R/conformal_infer_cv.R b/R/conformal_infer_cv.R index 41a774c..79c2ebb 100644 --- a/R/conformal_infer_cv.R +++ b/R/conformal_infer_cv.R @@ -148,6 +148,23 @@ print.int_conformal_cv <- function(x, ...) { invisible(x) } +#' S3 methods to track which additional packages are needed for prediction +#' intervals via conformal inference +#' @param x a conformal interval object +#' @inheritParams generics::required_pkgs +#' @export +required_pkgs.int_conformal_cv <- function(x, infra = TRUE, ...) { + model_pkgs <- map(x$models, required_pkgs, infra = infra) + model_pkgs <- unlist(model_pkgs) + + if (infra) { + model_pkgs <- c(model_pkgs, "probably") + } + + model_pkgs <- unique(model_pkgs) + model_pkgs +} + # ------------------------------------------------------------------------------ # helpers diff --git a/R/conformal_infer_quantile.R b/R/conformal_infer_quantile.R index c2227b5..3f7803c 100644 --- a/R/conformal_infer_quantile.R +++ b/R/conformal_infer_quantile.R @@ -115,6 +115,20 @@ print.int_conformal_quantile <- function(x, ...) { invisible(x) } +#' @rdname required_pkgs.int_conformal_cv +#' @keywords internal +#' @export +required_pkgs.int_conformal_quantile <- function(x, infra = TRUE, ...) { + model_pkgs <- required_pkgs(x$wflow, infra = infra) + + if (infra) { + model_pkgs <- c(model_pkgs, "probably") + } + + model_pkgs <- unique(model_pkgs) + model_pkgs +} + #' @export #' @rdname predict.int_conformal_full predict.int_conformal_quantile <- function(object, new_data, ...) { diff --git a/R/conformal_infer_split.R b/R/conformal_infer_split.R index ddcfb4a..a8f38c3 100644 --- a/R/conformal_infer_split.R +++ b/R/conformal_infer_split.R @@ -94,6 +94,20 @@ print.int_conformal_split <- function(x, ...) { invisible(x) } +#' @rdname required_pkgs.int_conformal_cv +#' @keywords internal +#' @export +required_pkgs.int_conformal_split <- function(x, infra = TRUE, ...) { + model_pkgs <- required_pkgs(x$wflow, infra = infra) + + if (infra) { + model_pkgs <- c(model_pkgs, "probably") + } + + model_pkgs <- unique(model_pkgs) + model_pkgs +} + #' @export #' @rdname predict.int_conformal_full predict.int_conformal_split <- function(object, new_data, level = 0.95, ...) { diff --git a/man/int_conformal_full.Rd b/man/int_conformal_full.Rd index 09faf20..e950fe7 100644 --- a/man/int_conformal_full.Rd +++ b/man/int_conformal_full.Rd @@ -68,6 +68,77 @@ the initial set of training set residuals are modeled using a Gamma generalized linear model with a log link (see the reference by Aitkin below). For a new sample, the absolute size of the residual is estimated and a multiple of this value is computed as an initial guess of the search boundaries. + +\subsection{Speed}{ + +The time it takes to compute the intervals depends on the training set +size, search parameters (i.e., convergence criterion, number of +iterations), the grid size, and the number of worker processes that are +used. For the last item, the computations can be parallelized using the +future and furrr packages. + +To use parallelism, the \code{\link[future:plan]{future::plan()}} function can +be invoked to create a parallel backend. For example, let’s make an +initial workflow: + +\if{html}{\out{