- 
                Notifications
    
You must be signed in to change notification settings  - Fork 16
 
add butcher methods for all int_conform methods #194
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,173 @@ | ||
| #' Butcher methods for conformal inteference intervals | ||
| #' | ||
| #' These methods allow you to use the butcher package to reduce the size of a | ||
| #' conformal inference interval object. After calling `butcher::butcher()` on a | ||
| #' conformal inference interval object, the only guarantee is that you will | ||
| #' still be able to `predict()` from that conformal inference interval object. | ||
| #' Other functions may not work as expected. | ||
| #' | ||
| #' @param x A conformal inference interval object. | ||
| #' @param verbose Should information be printed about how much memory is freed | ||
| #' from butchering? | ||
| #' @param ... Extra arguments possibly used by underlying methods. | ||
| #' | ||
| #' @keywords internal | ||
| #' @name inf_conformal-butcher | ||
| 
     | 
||
| # int_conformal_full | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_call.int_conformal_full <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_call(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| 
         There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for not directly exporting the method? The help page for  There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm doing it the same way that it was done in {workflows} https://github.com/tidymodels/workflows/blob/db117b59d8c545a55fd57eeb339ad232616e38a8/R/zzz.R#L6-L10 It didn't work when I did it the normal way. So it might be a little out of my depth to understand why. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fairly sure that the reason for this in workflows is because butcher is only in Suggests and not in Imports. Maybe that affects things here because we make use of the workflows methods, which don't seem to be exported from workflows? 🤔 I'm okay moving on and getting this merged though!  | 
||
| #' @rdname inf_conformal-butcher | ||
| axe_ctrl.int_conformal_full <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_ctrl(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_data.int_conformal_full <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_data(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_env.int_conformal_full <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_env(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_fitted.int_conformal_full <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_fitted(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # int_conformal_split | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_call.int_conformal_split <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_call(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_ctrl.int_conformal_split <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_ctrl(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_data.int_conformal_split <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_data(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_env.int_conformal_split <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_env(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_fitted.int_conformal_split <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_fitted(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # int_conformal_quantile | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_call.int_conformal_quantile <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_call(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_ctrl.int_conformal_quantile <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_ctrl(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_data.int_conformal_quantile <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_data(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_env.int_conformal_quantile <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_env(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_fitted.int_conformal_quantile <- function(x, verbose = FALSE, ...) { | ||
| x$wflow <- butcher::axe_fitted(x$wflow, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # int_conformal_cv | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_call.int_conformal_cv <- function(x, verbose = FALSE, ...) { | ||
| x$models <- purrr::map(x$models, butcher::axe_call, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_ctrl.int_conformal_cv <- function(x, verbose = FALSE, ...) { | ||
| x$models <- purrr::map(x$models, butcher::axe_ctrl, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_data.int_conformal_cv <- function(x, verbose = FALSE, ...) { | ||
| x$models <- purrr::map(x$models, butcher::axe_data, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_env.int_conformal_cv <- function(x, verbose = FALSE, ...) { | ||
| x$models <- purrr::map(x$models, butcher::axe_env, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # @export - onLoad | ||
| #' @rdname inf_conformal-butcher | ||
| axe_fitted.int_conformal_cv <- function(x, verbose = FALSE, ...) { | ||
| x$models <- purrr::map(x$models, butcher::axe_fitted, verbose = verbose, ...) | ||
| add_butcher_class(x) | ||
| } | ||
| 
     | 
||
| # ------------------------------------------------------------------------------ | ||
| 
     | 
||
| # butcher:::add_butcher_class | ||
| add_butcher_class <- function(x) { | ||
| if (!any(grepl("butcher", class(x)))) { | ||
| class(x) <- append(paste0("butchered_", rev(class(x))[1]), class(x)) | ||
| } | ||
| x | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,4 +1,28 @@ | ||
| .onLoad <- function(libname, pkgname) { | ||
| vctrs::s3_register("tune::collect_metrics", "cal_rset") | ||
| vctrs::s3_register("tune::collect_predictions", "cal_rset") | ||
| 
     | 
||
| vctrs::s3_register("butcher::axe_call", "int_conformal_cv") | ||
| vctrs::s3_register("butcher::axe_ctrl", "int_conformal_cv") | ||
| vctrs::s3_register("butcher::axe_data", "int_conformal_cv") | ||
| vctrs::s3_register("butcher::axe_env", "int_conformal_cv") | ||
| vctrs::s3_register("butcher::axe_fitted", "int_conformal_cv") | ||
| 
     | 
||
| vctrs::s3_register("butcher::axe_call", "int_conformal_full") | ||
| vctrs::s3_register("butcher::axe_ctrl", "int_conformal_full") | ||
| vctrs::s3_register("butcher::axe_data", "int_conformal_full") | ||
| vctrs::s3_register("butcher::axe_env", "int_conformal_full") | ||
| vctrs::s3_register("butcher::axe_fitted", "int_conformal_full") | ||
| 
     | 
||
| vctrs::s3_register("butcher::axe_call", "int_conformal_split") | ||
| vctrs::s3_register("butcher::axe_ctrl", "int_conformal_split") | ||
| vctrs::s3_register("butcher::axe_data", "int_conformal_split") | ||
| vctrs::s3_register("butcher::axe_env", "int_conformal_split") | ||
| vctrs::s3_register("butcher::axe_fitted", "int_conformal_split") | ||
| 
     | 
||
| vctrs::s3_register("butcher::axe_call", "int_conformal_quantile") | ||
| vctrs::s3_register("butcher::axe_ctrl", "int_conformal_quantile") | ||
| vctrs::s3_register("butcher::axe_data", "int_conformal_quantile") | ||
| vctrs::s3_register("butcher::axe_env", "int_conformal_quantile") | ||
| vctrs::s3_register("butcher::axe_fitted", "int_conformal_quantile") | ||
| } | 
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that there is a good amount of repetition. However the functions are also really short, so I think that this is the more readable form
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind but maybe they should all share a
int_conformalclass?