Skip to content

Commit d210d09

Browse files
add butcher methods for all int_conform methods (#194)
1 parent 571f838 commit d210d09

File tree

6 files changed

+393
-0
lines changed

6 files changed

+393
-0
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Roxygen: list(markdown = TRUE)
6363
RoxygenNote: 7.3.3
6464
Collate:
6565
'bound_prediction.R'
66+
'butcher.R'
6667
'cal-apply-binary.R'
6768
'cal-apply-impl.R'
6869
'cal-apply-multi.R'

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
* Add `required_pkgs()` methods to `int_conformal_cv()`, `int_conformal_full()`, `int_conformal_quantile()`, and `int_conformal_split()`. (#190)
44

5+
* Add butcher methods to `int_conformal_cv()`, `int_conformal_full()`, `int_conformal_quantile()`, and `int_conformal_split()`. (#194)
6+
57
# probably 1.1.1
68

79
* Updated unit tests for new ggplot2 release (#180).

R/butcher.R

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
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+
}

R/zzz.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
11
.onLoad <- function(libname, pkgname) {
22
vctrs::s3_register("tune::collect_metrics", "cal_rset")
33
vctrs::s3_register("tune::collect_predictions", "cal_rset")
4+
5+
vctrs::s3_register("butcher::axe_call", "int_conformal_cv")
6+
vctrs::s3_register("butcher::axe_ctrl", "int_conformal_cv")
7+
vctrs::s3_register("butcher::axe_data", "int_conformal_cv")
8+
vctrs::s3_register("butcher::axe_env", "int_conformal_cv")
9+
vctrs::s3_register("butcher::axe_fitted", "int_conformal_cv")
10+
11+
vctrs::s3_register("butcher::axe_call", "int_conformal_full")
12+
vctrs::s3_register("butcher::axe_ctrl", "int_conformal_full")
13+
vctrs::s3_register("butcher::axe_data", "int_conformal_full")
14+
vctrs::s3_register("butcher::axe_env", "int_conformal_full")
15+
vctrs::s3_register("butcher::axe_fitted", "int_conformal_full")
16+
17+
vctrs::s3_register("butcher::axe_call", "int_conformal_split")
18+
vctrs::s3_register("butcher::axe_ctrl", "int_conformal_split")
19+
vctrs::s3_register("butcher::axe_data", "int_conformal_split")
20+
vctrs::s3_register("butcher::axe_env", "int_conformal_split")
21+
vctrs::s3_register("butcher::axe_fitted", "int_conformal_split")
22+
23+
vctrs::s3_register("butcher::axe_call", "int_conformal_quantile")
24+
vctrs::s3_register("butcher::axe_ctrl", "int_conformal_quantile")
25+
vctrs::s3_register("butcher::axe_data", "int_conformal_quantile")
26+
vctrs::s3_register("butcher::axe_env", "int_conformal_quantile")
27+
vctrs::s3_register("butcher::axe_fitted", "int_conformal_quantile")
428
}

man/inf_conformal-butcher.Rd

Lines changed: 82 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)