Skip to content

Commit c7d68ce

Browse files
simonpcouchhfrick
andauthored
add parameters for postprocessing with tailor (#358)
* add `buffer()` for `adjust_equivocal_zone()` * add `*_limit()`s for `adjust_numeric_range()` * add NEWS entry * correct `inheritParams` * update pkgdown index --------- Co-authored-by: Hannah Frick <[email protected]>
1 parent caeee86 commit c7d68ce

8 files changed

+146
-0
lines changed

NAMESPACE

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export(activation_2)
5252
export(adjust_deg_free)
5353
export(all_neighbors)
5454
export(batch_size)
55+
export(buffer)
5556
export(class_weights)
5657
export(conditional_min_criterion)
5758
export(conditional_test_statistic)
@@ -93,6 +94,7 @@ export(is_unknown)
9394
export(kernel_offset)
9495
export(learn_rate)
9596
export(loss_reduction)
97+
export(lower_limit)
9698
export(lower_quantile)
9799
export(max_nodes)
98100
export(max_num_terms)
@@ -184,6 +186,7 @@ export(unbiased_rules)
184186
export(under_ratio)
185187
export(unique_cut)
186188
export(unknown)
189+
export(upper_limit)
187190
export(validation_set_prop)
188191
export(value_inverse)
189192
export(value_sample)

NEWS.md

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# dials (development version)
22

3+
* Added three new parameters for use in postprocessing in the tailor package (#357).
4+
- `buffer()` sets the distance on either side of a classification threshold
5+
within which predictions are considered equivocal in
6+
`tailor::adjust_equivocal_zone()`.
7+
- `lower_limit()` and `upper_limit()` sets the ranges for
8+
numeric predictions in `tailor::adjust_numeric_range()`.
9+
310
* All messages, warnings and errors has been translated to use {cli} package (#311).
411

512
# dials 1.3.0

R/param_buffer.R

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#' Buffer size
2+
#'
3+
#' In equivocal zones, predictions are considered equivocal (i.e. "could
4+
#' go either way") if their probability falls within some distance on either
5+
#' side of the classification threshold. That distance is called the "buffer."
6+
#'
7+
#' A buffer of .5 is only possible if the classification threshold is .5.
8+
#' In that case, all probability predictions are considered equivocal,
9+
#' regardless of their value in \code{[0, 1]}.
10+
#' Otherwise, the maximum buffer is `min(threshold, 1 - threshold)`.
11+
#'
12+
#' @inheritParams Laplace
13+
#' @seealso [threshold()]
14+
#' @examples
15+
#' buffer()
16+
#' @export
17+
buffer <- function(range = c(0, .5), trans = NULL) {
18+
new_quant_param(
19+
type = "double",
20+
range = range,
21+
inclusive = c(TRUE, TRUE),
22+
trans = trans,
23+
label = c(buffer = "buffer"),
24+
finalize = NULL
25+
)
26+
}

R/param_range_limits.R

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#' Limits for the range of predictions
2+
#'
3+
#' Range limits truncate model predictions to a specific range of values,
4+
#' typically to avoid extreme or unrealistic predictions.
5+
#'
6+
#' @inheritParams Laplace
7+
#' @examples
8+
#' lower_limit()
9+
#' upper_limit()
10+
#' @name range_limits
11+
#' @export
12+
13+
#' @rdname range_limits
14+
#' @export
15+
lower_limit <- function(range = c(-Inf, Inf), trans = NULL) {
16+
new_quant_param(
17+
type = "double",
18+
range = range,
19+
inclusive = c(TRUE, FALSE),
20+
trans = trans,
21+
label = c(lower_limit = "Lower Limit"),
22+
finalize = NULL
23+
)
24+
}
25+
26+
#' @rdname range_limits
27+
#' @export
28+
upper_limit <- function(range = c(-Inf, Inf), trans = NULL) {
29+
new_quant_param(
30+
type = "double",
31+
range = range,
32+
inclusive = c(FALSE, TRUE),
33+
trans = trans,
34+
label = c(upper_limit = "Upper Limit"),
35+
finalize = NULL
36+
)
37+
}

_pkgdown.yml

+5
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ reference:
112112
- scale_pos_weight
113113
- shrinkage_correlation
114114

115+
- title: Parameter objects for post-processing
116+
contents:
117+
- buffer
118+
- range_limits
119+
115120
- title: Finalizing parameters
116121
contents:
117122
- finalize

man/buffer.Rd

+35
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/range_limits.Rd

+30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-params.R

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ test_that("param ranges", {
44
expect_equal(sample_size(1:2)$range, list(lower = 1L, upper = 2L))
55
expect_equal(learn_rate(c(.1, .9))$range, list(lower = 0.1, upper = 0.9))
66
expect_equal(loss_reduction(c(.1, .9))$range, list(lower = 0.1, upper = 0.9))
7+
expect_equal(buffer(c(0, .25))$range, list(lower = 0, upper = .25))
78
expect_equal(cost_complexity(c(.1, .9))$range, list(lower = 0.1, upper = 0.9))
89
expect_equal(epochs(1:2)$range, list(lower = 1L, upper = 2L))
910
expect_equal(degree()$range, list(lower = 1, upper = 3))
@@ -83,6 +84,8 @@ test_that("param ranges", {
8384
expect_equal(harmonic_frequency(c(2, 100))$range, list(lower = 2, upper = 100))
8485
expect_equal(validation_set_prop(c(0.1, 0.4))$range, list(lower = 0.1, upper = 0.4))
8586
expect_equal(target_weight(c(0.1, 0.4))$range, list(lower = 0.1, upper = 0.4))
87+
expect_equal(lower_limit(c(Inf, 0))$range, list(lower = Inf, upper = 0))
88+
expect_equal(upper_limit(c(0, Inf))$range, list(lower = 0, upper = Inf))
8689
})
8790

8891

0 commit comments

Comments
 (0)