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
83 changes: 83 additions & 0 deletions R/learner_laGP_regr_laGP.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#' @title Regression Local Approximate Gaussian Process Learner
#' @author awinterstetter
#' @name mlr_learners_regr.laGP
#'
#' @description
#' Local approximate Gaussian process for regression.
#' Calls [laGP::aGP()] from \CRANpkg{laGP}.
#' Parameters `start` and `end` tune the initial and maximum neighborhood sizes
#' used for the local GP fit, `d` can fix the length-scale parameters, `g`
#' configures the nugget/regularization term, and `method` selects the search
#' heuristic (`alc`, `alcray`, `efi`, `mspe`, `nn`). Arguments `close` and
#' `numrays` further refine the ray-based search used by `method = "alcray"`,
#' while `verb` controls the output verbosity.
#'
#' @templateVar id regr.laGP
#' @template learner
#'
#' @export
#' @template seealso_learner
#' @template example
LearnerRegrLaGP = R6Class("LearnerRegrLaGP",
inherit = LearnerRegr,

public = list(

#' @description
#' Creates a new instance of this [R6][R6::R6Class] class.
initialize = function() {

ps = ps(
start = p_int(default = 6L, lower = 6L, tags = "predict"),
end = p_int(default = 50L, lower = 6L, tags = "predict"), # >start? check with Marc
d = p_uty(default = NULL, special_vals = list(NULL), tags = "predict"),
g = p_uty(default = 1 / 10000, tags = "predict"),
method = p_fct(default = "alc",
levels = c("alc", "alcray", "efi", "mspe", "nn"),
tags = "predict"),
close = p_int(lower = 0L, tags = "predict"),
numrays = p_int(lower = 0L, depends = method == "alcray", tags = "predict"),
verb = p_dbl(default = 0, tags = "predict")
)

super$initialize(
id = "regr.laGP",
packages = c("mlr3extralearners", "laGP"),
feature_types = c("integer", "numeric"),
predict_types = c("response", "se"),
param_set = ps,
label = "Local Approximate Gaussian Process",
man = "mlr3extralearners::mlr_learners_regr.laGP"
)
}
),

private = list(
.train = function(task) {
list(
X = as_numeric_matrix(task$data(cols = task$feature_names)),
Z = task$truth()
)
},

.predict = function(task) {
pars = self$param_set$get_values(tags = "predict")
pred = invoke(
laGP::aGP,
X = self$model$X,
Z = self$model$Z,
XX = as_numeric_matrix(ordered_features(task, self)),
Xi.ret = FALSE,
.args = pars
)

if (self$predict_type == "response") {
list(response = as.numeric(pred$mean))
} else {
list(response = as.numeric(pred$mean), se = sqrt(pred$var))
}
}
)
)

.extralrns_dict$add("regr.laGP", LearnerRegrLaGP)
143 changes: 143 additions & 0 deletions man/mlr_learners_regr.laGP.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test_laGP_regr_laGP.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
skip_if_not_installed("laGP")

test_that("autotest", {
learner = lrn("regr.laGP", end = 15) # I need to use sensible values here -> check with Marc?; with 15 it works
browser()
expect_learner(learner)
result = run_autotest(learner)
expect_true(result)
})
12 changes: 12 additions & 0 deletions tests/testthat/test_paramtest_laGP_regr_laGP.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
skip_if_not_installed("laGP")

test_that("paramtest regr.laGP predict", {
learner = lrn("regr.laGP")
fun = laGP::aGP

tested = c("start", "end", "d", "g", "method", "close", "numrays", "verb")
exclude = setdiff(names(formals(fun)), tested)

paramtest = run_paramtest(learner, fun, exclude, tag = "predict")
expect_paramtest(paramtest)
})
Loading