|
| 1 | +#' Butcher methods for conformal inteference intervals |
| 2 | +#' |
| 3 | +#' These methods allow you to use the butcher package to reduce the size of a |
| 4 | +#' conformal inference interval object. After calling `butcher::butcher()` on a |
| 5 | +#' conformal inference interval object, the only guarantee is that you will |
| 6 | +#' still be able to `predict()` from that conformal inference interval object. |
| 7 | +#' Other functions may not work as expected. |
| 8 | +#' |
| 9 | +#' @param x A conformal inference interval object. |
| 10 | +#' @param verbose Should information be printed about how much memory is freed |
| 11 | +#' from butchering? |
| 12 | +#' @param ... Extra arguments possibly used by underlying methods. |
| 13 | +#' |
| 14 | +#' @keywords internal |
| 15 | +#' @name inf_conformal-butcher |
| 16 | + |
| 17 | +# int_conformal_full |
| 18 | + |
| 19 | +# @export - onLoad |
| 20 | +#' @rdname inf_conformal-butcher |
| 21 | +axe_call.int_conformal_full <- function(x, verbose = FALSE, ...) { |
| 22 | + x$wflow <- butcher::axe_call(x$wflow, verbose = verbose, ...) |
| 23 | + add_butcher_class(x) |
| 24 | +} |
| 25 | + |
| 26 | +# @export - onLoad |
| 27 | +#' @rdname inf_conformal-butcher |
| 28 | +axe_ctrl.int_conformal_full <- function(x, verbose = FALSE, ...) { |
| 29 | + x$wflow <- butcher::axe_ctrl(x$wflow, verbose = verbose, ...) |
| 30 | + add_butcher_class(x) |
| 31 | +} |
| 32 | + |
| 33 | +# @export - onLoad |
| 34 | +#' @rdname inf_conformal-butcher |
| 35 | +axe_data.int_conformal_full <- function(x, verbose = FALSE, ...) { |
| 36 | + x$wflow <- butcher::axe_data(x$wflow, verbose = verbose, ...) |
| 37 | + add_butcher_class(x) |
| 38 | +} |
| 39 | + |
| 40 | +# @export - onLoad |
| 41 | +#' @rdname inf_conformal-butcher |
| 42 | +axe_env.int_conformal_full <- function(x, verbose = FALSE, ...) { |
| 43 | + x$wflow <- butcher::axe_env(x$wflow, verbose = verbose, ...) |
| 44 | + add_butcher_class(x) |
| 45 | +} |
| 46 | + |
| 47 | +# @export - onLoad |
| 48 | +#' @rdname inf_conformal-butcher |
| 49 | +axe_fitted.int_conformal_full <- function(x, verbose = FALSE, ...) { |
| 50 | + x$wflow <- butcher::axe_fitted(x$wflow, verbose = verbose, ...) |
| 51 | + add_butcher_class(x) |
| 52 | +} |
| 53 | + |
| 54 | +# int_conformal_split |
| 55 | + |
| 56 | +# @export - onLoad |
| 57 | +#' @rdname inf_conformal-butcher |
| 58 | +axe_call.int_conformal_split <- function(x, verbose = FALSE, ...) { |
| 59 | + x$wflow <- butcher::axe_call(x$wflow, verbose = verbose, ...) |
| 60 | + add_butcher_class(x) |
| 61 | +} |
| 62 | + |
| 63 | +# @export - onLoad |
| 64 | +#' @rdname inf_conformal-butcher |
| 65 | +axe_ctrl.int_conformal_split <- function(x, verbose = FALSE, ...) { |
| 66 | + x$wflow <- butcher::axe_ctrl(x$wflow, verbose = verbose, ...) |
| 67 | + add_butcher_class(x) |
| 68 | +} |
| 69 | + |
| 70 | +# @export - onLoad |
| 71 | +#' @rdname inf_conformal-butcher |
| 72 | +axe_data.int_conformal_split <- function(x, verbose = FALSE, ...) { |
| 73 | + x$wflow <- butcher::axe_data(x$wflow, verbose = verbose, ...) |
| 74 | + add_butcher_class(x) |
| 75 | +} |
| 76 | + |
| 77 | +# @export - onLoad |
| 78 | +#' @rdname inf_conformal-butcher |
| 79 | +axe_env.int_conformal_split <- function(x, verbose = FALSE, ...) { |
| 80 | + x$wflow <- butcher::axe_env(x$wflow, verbose = verbose, ...) |
| 81 | + add_butcher_class(x) |
| 82 | +} |
| 83 | + |
| 84 | +# @export - onLoad |
| 85 | +#' @rdname inf_conformal-butcher |
| 86 | +axe_fitted.int_conformal_split <- function(x, verbose = FALSE, ...) { |
| 87 | + x$wflow <- butcher::axe_fitted(x$wflow, verbose = verbose, ...) |
| 88 | + add_butcher_class(x) |
| 89 | +} |
| 90 | + |
| 91 | +# int_conformal_quantile |
| 92 | + |
| 93 | +# @export - onLoad |
| 94 | +#' @rdname inf_conformal-butcher |
| 95 | +axe_call.int_conformal_quantile <- function(x, verbose = FALSE, ...) { |
| 96 | + x$wflow <- butcher::axe_call(x$wflow, verbose = verbose, ...) |
| 97 | + add_butcher_class(x) |
| 98 | +} |
| 99 | + |
| 100 | +# @export - onLoad |
| 101 | +#' @rdname inf_conformal-butcher |
| 102 | +axe_ctrl.int_conformal_quantile <- function(x, verbose = FALSE, ...) { |
| 103 | + x$wflow <- butcher::axe_ctrl(x$wflow, verbose = verbose, ...) |
| 104 | + add_butcher_class(x) |
| 105 | +} |
| 106 | + |
| 107 | +# @export - onLoad |
| 108 | +#' @rdname inf_conformal-butcher |
| 109 | +axe_data.int_conformal_quantile <- function(x, verbose = FALSE, ...) { |
| 110 | + x$wflow <- butcher::axe_data(x$wflow, verbose = verbose, ...) |
| 111 | + add_butcher_class(x) |
| 112 | +} |
| 113 | + |
| 114 | +# @export - onLoad |
| 115 | +#' @rdname inf_conformal-butcher |
| 116 | +axe_env.int_conformal_quantile <- function(x, verbose = FALSE, ...) { |
| 117 | + x$wflow <- butcher::axe_env(x$wflow, verbose = verbose, ...) |
| 118 | + add_butcher_class(x) |
| 119 | +} |
| 120 | + |
| 121 | +# @export - onLoad |
| 122 | +#' @rdname inf_conformal-butcher |
| 123 | +axe_fitted.int_conformal_quantile <- function(x, verbose = FALSE, ...) { |
| 124 | + x$wflow <- butcher::axe_fitted(x$wflow, verbose = verbose, ...) |
| 125 | + add_butcher_class(x) |
| 126 | +} |
| 127 | + |
| 128 | +# int_conformal_cv |
| 129 | + |
| 130 | +# @export - onLoad |
| 131 | +#' @rdname inf_conformal-butcher |
| 132 | +axe_call.int_conformal_cv <- function(x, verbose = FALSE, ...) { |
| 133 | + x$models <- purrr::map(x$models, butcher::axe_call, verbose = verbose, ...) |
| 134 | + add_butcher_class(x) |
| 135 | +} |
| 136 | + |
| 137 | +# @export - onLoad |
| 138 | +#' @rdname inf_conformal-butcher |
| 139 | +axe_ctrl.int_conformal_cv <- function(x, verbose = FALSE, ...) { |
| 140 | + x$models <- purrr::map(x$models, butcher::axe_ctrl, verbose = verbose, ...) |
| 141 | + add_butcher_class(x) |
| 142 | +} |
| 143 | + |
| 144 | +# @export - onLoad |
| 145 | +#' @rdname inf_conformal-butcher |
| 146 | +axe_data.int_conformal_cv <- function(x, verbose = FALSE, ...) { |
| 147 | + x$models <- purrr::map(x$models, butcher::axe_data, verbose = verbose, ...) |
| 148 | + add_butcher_class(x) |
| 149 | +} |
| 150 | + |
| 151 | +# @export - onLoad |
| 152 | +#' @rdname inf_conformal-butcher |
| 153 | +axe_env.int_conformal_cv <- function(x, verbose = FALSE, ...) { |
| 154 | + x$models <- purrr::map(x$models, butcher::axe_env, verbose = verbose, ...) |
| 155 | + add_butcher_class(x) |
| 156 | +} |
| 157 | + |
| 158 | +# @export - onLoad |
| 159 | +#' @rdname inf_conformal-butcher |
| 160 | +axe_fitted.int_conformal_cv <- function(x, verbose = FALSE, ...) { |
| 161 | + x$models <- purrr::map(x$models, butcher::axe_fitted, verbose = verbose, ...) |
| 162 | + add_butcher_class(x) |
| 163 | +} |
| 164 | + |
| 165 | +# ------------------------------------------------------------------------------ |
| 166 | + |
| 167 | +# butcher:::add_butcher_class |
| 168 | +add_butcher_class <- function(x) { |
| 169 | + if (!any(grepl("butcher", class(x)))) { |
| 170 | + class(x) <- append(paste0("butchered_", rev(class(x))[1]), class(x)) |
| 171 | + } |
| 172 | + x |
| 173 | +} |
0 commit comments