Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
- `LearnerRegrPcr`
- `LearnerRegrPlsr`
- `LearnerRegrLaGP`
- `LearnerRegrFrbs`
- `LearnerRegrBgp`
- `LearnerRegrBgpllm`
- `LearnerRegrBtgp`
- `LearnerRegrBtlm`


## Breaking Changes

Expand Down
4 changes: 2 additions & 2 deletions R/learner_RRF_regr_RRF.R
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ LearnerRegrRRF = R6Class("LearnerRegrRRF",
.train = function(task) {
pars = self$param_set$get_values(tags = "train")

mlr3misc::invoke(RRF::RRF,
invoke(RRF::RRF,
formula = task$formula(),
data = task$data(),
.args = pars)
Expand All @@ -104,7 +104,7 @@ LearnerRegrRRF = R6Class("LearnerRegrRRF",
pars = self$param_set$get_values(tags = "predict")
newdata = ordered_features(task, self)

pred = mlr3misc::invoke(predict,
pred = invoke(predict,
object = self$model,
newdata = newdata,
type = self$predict_type,
Expand Down
2 changes: 1 addition & 1 deletion R/learner_frbs_regr_frbs.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ LearnerRegrFrbs = R6Class("LearnerRegrFrbs",

.predict = function(task) {
newdata = as.matrix(ordered_features(task, self), drop = FALSE)
pred = mlr3misc::invoke(predict, object = self$model, newdata = newdata)
pred = invoke(predict, object = self$model, newdata = newdata)

if (is.matrix(pred) || is.data.frame(pred)) {
pred = pred[, 1L]
Expand Down
4 changes: 2 additions & 2 deletions R/learner_pls_regr_plsr.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ LearnerRegrPlsr = R6Class("LearnerRegrPlsr",
quote = c("left", "right"),
env = environment())

mlr3misc::invoke(pls::plsr,
invoke(pls::plsr,
formula = formula,
data = task$data(),
.args = pars)
Expand All @@ -66,7 +66,7 @@ LearnerRegrPlsr = R6Class("LearnerRegrPlsr",
pars = self$param_set$get_values(tags = "predict")
newdata = ordered_features(task, self)

pred = mlr3misc::invoke(predict, self$model,
pred = invoke(predict, self$model,
newdata = newdata,
type = "response",
# specifying comps forces that pred is a matrix
Expand Down
32 changes: 17 additions & 15 deletions R/learner_tgp_regr_bgp.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#'
#' @section Initial parameter values:
#' * `verb` is initialized to `0` to silence printing.
#' * `pred.n` is initialized to `FALSE` to skip prediction during training.
#'
#' @templateVar id regr.bgp
#' @template learner
Expand All @@ -26,27 +27,27 @@ LearnerRegrBgp = R6Class("LearnerRegrBgp",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
meanfn = p_fct(default = "linear", levels = c("constant", "linear"), tags = "train"),
bprior = p_fct(default = "bflat", levels = c("b0", "b0not", "bflat", "bmle", "bmznot", "bmzt"), tags = "train"),
BTE = p_uty(default = c(1000L, 4000L, 2L), tags = c("train", "predict"), custom_check = mlr3misc::crate({function(x) {
corr = p_fct(default = "expsep", levels = c("exp", "expsep", "matern", "sim"), tags = "train"),
BTE = p_uty(default = c(1000L, 4000L, 2L), tags = c("train", "predict"), custom_check = mlr3misc::crate({function(x) {
if (!checkmate::test_integerish(x, len = 3, lower = 0)) {
return("`BTE` must be an integerish vector of length 3 with non-negative entries")
}
TRUE
}})),
corr = p_fct(default = "expsep", levels = c("exp", "expsep", "matern", "sim"), tags = "train"),
Ds2x = p_lgl(default = FALSE, tags = c("train", "predict")),
improv = p_lgl(default = FALSE, tags = c("train", "predict")),
R = p_int(default = 1L, lower = 1L, tags = c("train", "predict")),
m0r1 = p_lgl(default = TRUE, tags = "train"),
itemps = p_uty(default = NULL, tags = "train"),
pred.n = p_lgl(init = FALSE, tags = c("train", "predict")),
krige = p_lgl(default = TRUE, tags = c("train", "predict")),
m0r1 = p_lgl(default = TRUE, tags = "train"),
MAP = p_lgl(default = TRUE, tags = "predict"),
meanfn = p_fct(default = "linear", levels = c("constant", "linear"), tags = "train"),
zcov = p_lgl(default = FALSE, tags = c("train", "predict")),
Ds2x = p_lgl(default = FALSE, tags = c("train", "predict")),
improv = p_lgl(default = FALSE, tags = c("train", "predict")),
nu = p_dbl(default = 1.5, tags = "train", depends = quote(corr == "matern")),
R = p_int(default = 1L, lower = 1L, tags = c("train", "predict")),
sens.p = p_uty(default = NULL, tags = c("train", "predict")),
trace = p_lgl(default = FALSE, tags = c("train", "predict")),
verb = p_int(init= 0L, lower = 0L, upper = 4L, tags = c("train", "predict")),
zcov = p_lgl(default = FALSE, tags = c("train", "predict"))
MAP = p_lgl(default = TRUE, tags = "predict")
)

super$initialize(
Expand All @@ -65,7 +66,7 @@ LearnerRegrBgp = R6Class("LearnerRegrBgp",
pars = self$param_set$get_values(tags = "train")
data = as_numeric_matrix(task$data(cols = task$feature_names))

mlr3misc::invoke(tgp::bgp,
invoke(tgp::bgp,
X = data,
Z = task$truth(),
.args = pars
Expand All @@ -76,7 +77,11 @@ LearnerRegrBgp = R6Class("LearnerRegrBgp",
pars = self$param_set$get_values(tags = "predict")
newdata = as_numeric_matrix(ordered_features(task, self))

pred = mlr3misc::invoke(predict,
if (self$predict_type == "se") {
pars$krige = TRUE
}

pred = invoke(predict,
object = self$model,
XX = newdata,
.args = pars
Expand All @@ -85,9 +90,6 @@ LearnerRegrBgp = R6Class("LearnerRegrBgp",
if (self$predict_type == "response") {
list(response = pred$ZZ.km)
} else {
if (is.null(pred$ZZ.ks2)) {
stop("Standard errors requested but `ZZ.ks2` was not returned; try setting `krige = TRUE`.")
}
list(response = pred$ZZ.km, se = sqrt(pred$ZZ.ks2))
}
}
Expand Down
42 changes: 22 additions & 20 deletions R/learner_tgp_regr_bgpllm.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#'
#' @section Initial parameter values:
#' * `verb` is initialized to `0` to silence printing.
#' * `pred.n` is initialized to `FALSE` to skip prediction during training.
#'
#' @templateVar id regr.bgpllm
#' @template learner
Expand All @@ -26,16 +27,10 @@ LearnerRegrBgpllm = R6Class("LearnerRegrBgpllm",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
meanfn = p_fct(default = "linear", levels = c("constant", "linear"), tags = "train"),
bprior = p_fct(default = "bflat", levels = c("b0", "b0not", "bflat", "bmle", "bmznot", "bmzt"), tags = "train"),
BTE = p_uty(default = c(2000L, 4000L, 2L), tags = c("train", "predict"), custom_check = mlr3misc::crate({function(x) {
if (!checkmate::test_integerish(x, len = 3, lower = 0)) {
return("`BTE` must be an integerish vector of length 3 with non-negative entries")
}
TRUE
}})),
corr = p_fct(default = "expsep", levels = c("exp", "expsep", "matern", "sim"), tags = "train"),
Ds2x = p_lgl(default = FALSE, tags = c("train", "predict")),
gamma = p_uty(default = c(10, 0.2, 0.7), tags = "train", custom_check = mlr3misc::crate({function(x) {
gamma = p_uty(default = c(10, 0.2, 0.7), tags = "train", custom_check = mlr3misc::crate({function(x) {
if (!checkmate::test_numeric(x, len = 3, lower = 0)) {
return("`gamma` must be a numeric vector of length 3 with non-negative entries")
}
Expand All @@ -44,18 +39,24 @@ LearnerRegrBgpllm = R6Class("LearnerRegrBgpllm",
}
TRUE
}})),
improv = p_lgl(default = FALSE, tags = c("train", "predict")),
BTE = p_uty(default = c(2000L, 4000L, 2L), tags = c("train", "predict"), custom_check = mlr3misc::crate({function(x) {
if (!checkmate::test_integerish(x, len = 3, lower = 0)) {
return("`BTE` must be an integerish vector of length 3 with non-negative entries")
}
TRUE
}})),
R = p_int(default = 1L, lower = 1L, tags = c("train", "predict")),
m0r1 = p_lgl(default = TRUE, tags = "train"),
itemps = p_uty(default = NULL, tags = "train"),
pred.n = p_lgl(init = FALSE, tags = c("train", "predict")),
krige = p_lgl(default = TRUE, tags = c("train", "predict")),
m0r1 = p_lgl(default = TRUE, tags = "train"),
MAP = p_lgl(default = TRUE, tags = "predict"),
meanfn = p_fct(default = "linear", levels = c("constant", "linear"), tags = "train"),
zcov = p_lgl(default = FALSE, tags = c("train", "predict")),
Ds2x = p_lgl(default = FALSE, tags = c("train", "predict")),
improv = p_lgl(default = FALSE, tags = c("train", "predict")),
nu = p_dbl(default = 1.5, tags = "train", depends = quote(corr == "matern")),
R = p_int(default = 1L, lower = 1L, tags = c("train", "predict")),
sens.p = p_uty(default = NULL, tags = c("train", "predict")),
trace = p_lgl(default = FALSE, tags = c("train", "predict")),
verb = p_int(init = 0L, lower = 0L, upper = 4L, tags = c("train", "predict")),
zcov = p_lgl(default = FALSE, tags = c("train", "predict"))
MAP = p_lgl(default = TRUE, tags = "predict")
)

super$initialize(
Expand All @@ -76,7 +77,7 @@ LearnerRegrBgpllm = R6Class("LearnerRegrBgpllm",
x = as_numeric_matrix(task$data(cols = task$feature_names))
y = task$truth()

mlr3misc::invoke(
invoke(
tgp::bgpllm,
X = x,
Z = y,
Expand All @@ -88,7 +89,11 @@ LearnerRegrBgpllm = R6Class("LearnerRegrBgpllm",

newdata = as_numeric_matrix(ordered_features(task, self))

pred = mlr3misc::invoke(
if (self$predict_type == "se") {
pars$krige = TRUE
}

pred = invoke(
predict,
self$model,
XX = newdata,
Expand All @@ -98,9 +103,6 @@ LearnerRegrBgpllm = R6Class("LearnerRegrBgpllm",
if (self$predict_type == "response") {
list(response = pred$ZZ.km)
} else {
if (is.null(pred$ZZ.ks2)) {
stop("Standard errors requested but `ZZ.ks2` was not returned; try setting `krige = TRUE`.")
}
list(response = pred$ZZ.km, se = sqrt(pred$ZZ.ks2))
}
}
Expand Down
49 changes: 29 additions & 20 deletions R/learner_tgp_regr_btgp.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
#' Bayesian treed Gaussian process regression model.
#' Calls [tgp::btgp()] from \CRANpkg{tgp}.
#' For the predicted mean `ZZ.km` and for the predicted variance `ZZ.ks2` are chosen.
#'
#' Factor features are one-hot encoded with reference encoding before fitting.
#' If factors are present, `basemax` is set to the number of non-factor features
#' so that tree proposals account for the numeric part of the design.
#'
#' @section Initial parameter values:
#' * `verb` is initialized to `0` to silence printing.
#' * `pred.n` is initialized to `FALSE` to skip prediction during training.
#'
#' @templateVar id regr.btgp
#' @template learner
Expand All @@ -26,36 +31,36 @@ LearnerRegrBtgp = R6Class("LearnerRegrBtgp",
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {
param_set = ps(
meanfn = p_fct(default = "linear", levels = c("constant", "linear"), tags = "train"),
bprior = p_fct(default = "bflat", levels = c("b0", "b0not", "bflat", "bmle", "bmznot", "bmzt"), tags = "train"),
corr = p_fct(default = "expsep", levels = c("exp", "expsep", "matern", "sim"), tags = "train"),
tree = p_uty(default = c(0.5, 2), tags = "train", custom_check = mlr3misc::crate({function(x) {
if (checkmate::test_numeric(x, len = 2, any.missing = FALSE)) {
if (x[1] >= 0 && x[1] <= 1 && x[2] >= 0) {
return(TRUE)
}
}
"`tree` must be numeric length 2 with first element in [0, 1] and second >= 0"
}})),
BTE = p_uty(default = c(2000L, 7000L, 2L), tags = c("train", "predict"), custom_check = mlr3misc::crate({function(x) {
if (!checkmate::test_integerish(x, len = 3, lower = 0)) {
return("`BTE` must be an integerish vector of length 3 with non-negative entries")
}
TRUE
}})),
corr = p_fct(default = "expsep", levels = c("exp", "expsep", "matern", "sim"), tags = "train"),
Ds2x = p_lgl(default = FALSE, tags = c("train", "predict")),
improv = p_lgl(default = FALSE, tags = c("train", "predict")),
R = p_int(default = 1L, lower = 1L, tags = c("train", "predict")),
m0r1 = p_lgl(default = TRUE, tags = "train"),
linburn = p_lgl(default = FALSE, tags = "train"),
itemps = p_uty(default = NULL, tags = "train"),
pred.n = p_lgl(init = FALSE, tags = c("train", "predict")),
krige = p_lgl(default = TRUE, tags = c("train", "predict")),
linburn = p_lgl(default = FALSE, tags = "train"),
m0r1 = p_lgl(default = TRUE, tags = "train"),
MAP = p_lgl(default = TRUE, tags = "predict"),
meanfn = p_fct(default = "linear", levels = c("constant", "linear"), tags = "train"),
zcov = p_lgl(default = FALSE, tags = c("train", "predict")),
Ds2x = p_lgl(default = FALSE, tags = c("train", "predict")),
improv = p_lgl(default = FALSE, tags = c("train", "predict")),
nu = p_dbl(default = 1.5, tags = "train", depends = quote(corr == "matern")),
R = p_int(default = 1L, lower = 1L, tags = c("train", "predict")),
sens.p = p_uty(default = NULL, tags = c("train", "predict")),
trace = p_lgl(default = FALSE, tags = c("train", "predict")),
tree = p_uty(default = c(0.5, 2), tags = "train", custom_check = mlr3misc::crate({function(x) {
if (checkmate::test_numeric(x, len = 2, any.missing = FALSE)) {
if (x[1] >= 0 && x[1] <= 1 && x[2] >= 0) {
return(TRUE)
}
}
"`tree` must be numeric length 2 with first element in [0, 1] and second >= 0"
}})),
verb = p_int(init = 0L, lower = 0L, upper = 4L, tags = c("train", "predict")),
zcov = p_lgl(default = FALSE, tags = c("train", "predict"))
MAP = p_lgl(default = TRUE, tags = "predict")
)

super$initialize(
Expand All @@ -79,7 +84,7 @@ LearnerRegrBtgp = R6Class("LearnerRegrBtgp",
pars$basemax = encoded$basemax
}

model = mlr3misc::invoke(tgp::btgp,
model = invoke(tgp::btgp,
X = encoded$data,
Z = task$truth(),
.args = pars
Expand All @@ -106,7 +111,11 @@ LearnerRegrBtgp = R6Class("LearnerRegrBtgp",
encoded$data = encoded$data[, self$model$column_names, drop = FALSE]
}

pred = mlr3misc::invoke(predict,
if (self$predict_type == "se") {
pars$krige = TRUE
}

pred = invoke(predict,
object = self$model$model,
XX = encoded$data,
.args = pars
Expand Down
Loading