Skip to content

Commit 2c3070c

Browse files
committed
operation -> adjustment (closes #19)
1 parent e4fc3c9 commit 2c3070c

18 files changed

+102
-102
lines changed

Diff for: R/adjust-equivocal-zone.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ adjust_equivocal_zone <- function(x, value = 0.1, threshold = 1 / 2) {
3232
check_number_decimal(threshold, min = 10^-10, max = 1 - 10^-10)
3333
}
3434

35-
op <-
36-
new_operation(
35+
adj <-
36+
new_adjustment(
3737
"equivocal_zone",
3838
inputs = "probability",
3939
outputs = "class",
@@ -45,7 +45,7 @@ adjust_equivocal_zone <- function(x, value = 0.1, threshold = 1 / 2) {
4545

4646
new_tailor(
4747
type = x$type,
48-
operations = c(x$operations, list(op)),
48+
adjustments = c(x$adjustments, list(adj)),
4949
columns = x$dat,
5050
ptype = x$ptype,
5151
call = current_env()
@@ -70,7 +70,7 @@ print.equivocal_zone <- function(x, ...) {
7070

7171
#' @export
7272
fit.equivocal_zone <- function(object, data, tailor = NULL, ...) {
73-
new_operation(
73+
new_adjustment(
7474
class(object),
7575
inputs = object$inputs,
7676
outputs = object$outputs,

Diff for: R/adjust-numeric-calibration.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ adjust_numeric_calibration <- function(x, method = NULL) {
3838
)
3939
}
4040

41-
op <-
42-
new_operation(
41+
adj <-
42+
new_adjustment(
4343
"numeric_calibration",
4444
inputs = "numeric",
4545
outputs = "numeric",
@@ -51,7 +51,7 @@ adjust_numeric_calibration <- function(x, method = NULL) {
5151

5252
new_tailor(
5353
type = x$type,
54-
operations = c(x$operations, list(op)),
54+
adjustments = c(x$adjustments, list(adj)),
5555
columns = x$dat,
5656
ptype = x$ptype,
5757
call = current_env()
@@ -81,7 +81,7 @@ fit.numeric_calibration <- function(object, data, tailor = NULL, ...) {
8181
)
8282
)
8383

84-
new_operation(
84+
new_adjustment(
8585
class(object),
8686
inputs = object$inputs,
8787
outputs = object$outputs,

Diff for: R/adjust-numeric-range.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ adjust_numeric_range <- function(x, lower_limit = -Inf, upper_limit = Inf) {
88
# remaining input checks are done via probably::bound_prediction
99
check_tailor(x)
1010

11-
op <-
12-
new_operation(
11+
adj <-
12+
new_adjustment(
1313
"numeric_range",
1414
inputs = "numeric",
1515
outputs = "numeric",
@@ -21,7 +21,7 @@ adjust_numeric_range <- function(x, lower_limit = -Inf, upper_limit = Inf) {
2121

2222
new_tailor(
2323
type = x$type,
24-
operations = c(x$operations, list(op)),
24+
adjustments = c(x$adjustments, list(adj)),
2525
columns = x$dat,
2626
ptype = x$ptype,
2727
call = current_env()
@@ -59,7 +59,7 @@ print.numeric_range <- function(x, ...) {
5959

6060
#' @export
6161
fit.numeric_range <- function(object, data, tailor = NULL, ...) {
62-
new_operation(
62+
new_adjustment(
6363
class(object),
6464
inputs = object$inputs,
6565
outputs = object$outputs,

Diff for: R/adjust-predictions-custom.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ adjust_predictions_custom <- function(x, ..., .pkgs = character(0)) {
2828
check_tailor(x)
2929
cmds <- enquos(...)
3030

31-
op <-
32-
new_operation(
31+
adj <-
32+
new_adjustment(
3333
"predictions_custom",
3434
inputs = "everything",
3535
outputs = "everything",
@@ -43,7 +43,7 @@ adjust_predictions_custom <- function(x, ..., .pkgs = character(0)) {
4343

4444
new_tailor(
4545
type = x$type,
46-
operations = c(x$operations, list(op)),
46+
adjustments = c(x$adjustments, list(adj)),
4747
columns = x$dat,
4848
ptype = x$ptype,
4949
call = current_env()
@@ -59,7 +59,7 @@ print.predictions_custom <- function(x, ...) {
5959

6060
#' @export
6161
fit.predictions_custom <- function(object, data, tailor = NULL, ...) {
62-
new_operation(
62+
new_adjustment(
6363
class(object),
6464
inputs = object$inputs,
6565
outputs = object$outputs,

Diff for: R/adjust-probability-calibration.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ adjust_probability_calibration <- function(x, method = NULL) {
1717
)
1818
}
1919

20-
op <-
21-
new_operation(
20+
adj <-
21+
new_adjustment(
2222
"probability_calibration",
2323
inputs = "probability",
2424
outputs = "probability_class",
@@ -30,7 +30,7 @@ adjust_probability_calibration <- function(x, method = NULL) {
3030

3131
new_tailor(
3232
type = x$type,
33-
operations = c(x$operations, list(op)),
33+
adjustments = c(x$adjustments, list(adj)),
3434
columns = x$dat,
3535
ptype = x$ptype,
3636
call = current_env()
@@ -62,7 +62,7 @@ fit.probability_calibration <- function(object, data, tailor = NULL, ...) {
6262
)
6363
)
6464

65-
new_operation(
65+
new_adjustment(
6666
class(object),
6767
inputs = object$inputs,
6868
outputs = object$outputs,

Diff for: R/adjust-probability-threshold.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ adjust_probability_threshold <- function(x, threshold = 0.5) {
2828
check_number_decimal(threshold, min = 10^-10, max = 1 - 10^-10)
2929
}
3030

31-
op <-
32-
new_operation(
31+
adj <-
32+
new_adjustment(
3333
"probability_threshold",
3434
inputs = "probability",
3535
outputs = "class",
@@ -41,7 +41,7 @@ adjust_probability_threshold <- function(x, threshold = 0.5) {
4141

4242
new_tailor(
4343
type = x$type,
44-
operations = c(x$operations, list(op)),
44+
adjustments = c(x$adjustments, list(adj)),
4545
columns = x$dat,
4646
ptype = x$ptype,
4747
call = current_env()
@@ -66,7 +66,7 @@ print.probability_threshold <- function(x, ...) {
6666

6767
#' @export
6868
fit.probability_threshold <- function(object, data, tailor = NULL, ...) {
69-
new_operation(
69+
new_adjustment(
7070
class(object),
7171
inputs = object$inputs,
7272
outputs = object$outputs,

Diff for: R/tailor.R

+24-24
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,33 @@ tailor <- function(type = "unknown", outcome = NULL, estimate = NULL,
2727

2828
new_tailor(
2929
type,
30-
operations = list(),
30+
adjustments = list(),
3131
columns = columns,
3232
ptype = tibble::new_tibble(list()),
3333
call = current_env()
3434
)
3535
}
3636

37-
new_tailor <- function(type, operations, columns, ptype, call) {
37+
new_tailor <- function(type, adjustments, columns, ptype, call) {
3838
type <- arg_match0(type, c("unknown", "regression", "binary", "multiclass"))
3939

40-
if (!is.list(operations)) {
41-
cli_abort("The {.arg operations} argument should be a list.", call = call)
40+
if (!is.list(adjustments)) {
41+
cli_abort("The {.arg adjustments} argument should be a list.", call = call)
4242
}
4343

44-
is_oper <- purrr::map_lgl(operations, ~ inherits(.x, "operation"))
45-
if (length(is_oper) > 0 && !any(is_oper)) {
46-
bad_oper <- names(is_oper)[!is_oper]
47-
cli_abort("The following {.arg operations} do not have the class \\
48-
{.val operation}: {bad_oper}.", call = call)
44+
is_adjustment <- purrr::map_lgl(adjustments, ~ inherits(.x, "adjustment"))
45+
if (length(is_adjustment) > 0 && !any(is_adjustment)) {
46+
bad_adjustment <- names(is_adjustment)[!is_adjustment]
47+
cli_abort("The following {.arg adjustments} do not have the class \\
48+
{.val adjustment}: {bad_adjustment}.", call = call)
4949
}
5050

51-
# validate operation order and check duplicates
52-
validate_order(operations, type, call)
51+
# validate adjustment order and check duplicates
52+
validate_order(adjustments, type, call)
5353

5454
# check columns
5555
res <- list(
56-
type = type, operations = operations,
56+
type = type, adjustments = adjustments,
5757
columns = columns, ptype = ptype
5858
)
5959
class(res) <- "tailor"
@@ -64,15 +64,15 @@ new_tailor <- function(type, operations, columns, ptype, call) {
6464
print.tailor <- function(x, ...) {
6565
cli::cli_h1("tailor")
6666

67-
num_op <- length(x$operations)
67+
num_adj <- length(x$adjustments)
6868
cli::cli_text(
6969
"A {ifelse(x$type == 'unknown', '', x$type)} postprocessor \\
70-
with {num_op} operation{?s}{cli::qty(num_op+1)}{?./:}"
70+
with {num_adj} adjustment{?s}{cli::qty(num_adj+1)}{?./:}"
7171
)
7272

73-
if (num_op > 0) {
73+
if (num_adj > 0) {
7474
cli::cli_text("\n")
75-
res <- purrr::map(x$operations, print)
75+
res <- purrr::map(x$adjustments, print)
7676
}
7777

7878
invisible(x)
@@ -112,16 +112,16 @@ fit.tailor <- function(object, .data, outcome, estimate, probabilities = c(),
112112

113113
object <- new_tailor(
114114
object$type,
115-
operations = object$operations,
115+
adjustments = object$adjustments,
116116
columns = columns,
117117
ptype = ptype,
118118
call = current_env()
119119
)
120120

121-
num_oper <- length(object$operations)
122-
for (op in seq_len(num_oper)) {
123-
object$operations[[op]] <- fit(object$operations[[op]], .data, object)
124-
.data <- predict(object$operations[[op]], .data, object)
121+
num_adjustment <- length(object$adjustments)
122+
for (adj in seq_len(num_adjustment)) {
123+
object$adjustments[[adj]] <- fit(object$adjustments[[adj]], .data, object)
124+
.data <- predict(object$adjustments[[adj]], .data, object)
125125
}
126126

127127
# todo Add a fitted tailor class?
@@ -131,9 +131,9 @@ fit.tailor <- function(object, .data, outcome, estimate, probabilities = c(),
131131
#' @export
132132
predict.tailor <- function(object, new_data, ...) {
133133
# validate levels/classes
134-
num_oper <- length(object$operations)
135-
for (op in seq_len(num_oper)) {
136-
new_data <- predict(object$operations[[op]], new_data, object)
134+
num_adjustment <- length(object$adjustments)
135+
for (adj in seq_len(num_adjustment)) {
136+
new_data <- predict(object$adjustments[[adj]], new_data, object)
137137
}
138138
if (!tibble::is_tibble(new_data)) {
139139
new_data <- tibble::as_tibble(new_data)

Diff for: R/utils.R

+9-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ is_tune <- function(x) {
1414
isTRUE(identical(quote(tune), x[[1]]))
1515
}
1616

17-
# for operations with no tunable parameters
17+
# for adjustments with no tunable parameters
1818

1919
no_param <-
2020
tibble::tibble(
@@ -33,7 +33,7 @@ no_param <-
3333
input_vals <- c("numeric", "probability", "class", "everything")
3434
output_vals <- c("numeric", "probability_class", "class", "everything")
3535

36-
new_operation <- function(cls, inputs, outputs, arguments, results = list(),
36+
new_adjustment <- function(cls, inputs, outputs, arguments, results = list(),
3737
trained, requires_fit, ...) {
3838
inputs <- arg_match0(inputs, input_vals)
3939
outputs <- arg_match0(outputs, output_vals)
@@ -49,7 +49,7 @@ new_operation <- function(cls, inputs, outputs, arguments, results = list(),
4949
trained = trained,
5050
requires_fit = requires_fit
5151
)
52-
class(res) <- c(cls, "operation")
52+
class(res) <- c(cls, "adjustment")
5353
res
5454
}
5555

@@ -62,25 +62,25 @@ is_tailor <- function(x) {
6262
#' @keywords internal
6363
#' @rdname tailor-internals
6464
tailor_fully_trained <- function(x) {
65-
if (length(x$operations) == 0L) {
65+
if (length(x$adjustments) == 0L) {
6666
return(FALSE)
6767
}
6868

69-
all(purrr::map_lgl(x$operations, tailor_operation_trained))
69+
all(purrr::map_lgl(x$adjustments, tailor_adjustment_trained))
7070
}
7171

72-
tailor_operation_trained <- function(x) {
72+
tailor_adjustment_trained <- function(x) {
7373
isTRUE(x$trained)
7474
}
7575

7676
#' @export
7777
#' @keywords internal
7878
#' @rdname tailor-internals
7979
tailor_requires_fit <- function(x) {
80-
any(purrr::map_lgl(x$operations, tailor_operation_requires_fit))
80+
any(purrr::map_lgl(x$adjustments, tailor_adjustment_requires_fit))
8181
}
8282

83-
tailor_operation_requires_fit <- function(x) {
83+
tailor_adjustment_requires_fit <- function(x) {
8484
isTRUE(x$requires_fit)
8585
}
8686

@@ -114,7 +114,7 @@ check_calibration_type <- function(calibration_type, calibration_type_expected,
114114
tailor_type, call) {
115115
if (!identical(calibration_type, calibration_type_expected)) {
116116
cli_abort(
117-
"A {.field {tailor_type}} tailor is incompatible with the operation \\
117+
"A {.field {tailor_type}} tailor is incompatible with the adjustment \\
118118
{.fun {paste0('adjust_', calibration_type, '_calibration')}}.",
119119
call = call
120120
)

0 commit comments

Comments
 (0)