R interface to Python's GPopt.GPOpt, the main class of the
GPopt package for minimizing a black-box, expensive-to-evaluate
objective function over a box-constrained search space.
GPOpt(
lower_bound,
upper_bound,
objective_func = NULL,
params_names = NULL,
surrogate_obj = NULL,
x_init = NULL,
y_init = NULL,
n_init = 10L,
n_choices = 100000L,
n_iter = 190L,
alpha = 1e-06,
n_restarts_optimizer = 25L,
seed = 123L,
save = NULL,
n_jobs = 1L,
acquisition = c("ei", "ucb"),
method = "bayesian",
min_value = NULL,
per_second = FALSE,
log_scale = FALSE,
venv_path = "./venv",
...
)numeric vector, lower bound for the parameters to optimize
numeric vector, upper bound for the parameters to optimize
an R function taking a single numeric vector `x` (1-indexed, as usual in R – e.g. `x[1]`, `x[2]`, ...) and returning a single numeric value to be minimized. Can be left `NULL`, e.g. when the optimizer state will be `$load()`-ed from disk.
optional character vector, names for the parameters (makes results easier to map back onto keyword arguments of an ML model)
optional surrogate model object (e.g. the result of [GenericSurrogate()], or any Python scikit-learn-compatible regressor obtained via [get_sklearn()]) used instead of the default Gaussian Process Regression surrogate
optional numeric matrix/vector with an existing initial design (`x_init`) and corresponding objective values (`y_init`)
number of points in the initial (space-filling) design
number of candidate points used when searching for the next evaluation point
number of iterations of the optimizer
numeric, GP regularization / noise parameter
number of restarts of the GP's internal hyperparameter optimizer
integer random seed
optional path (character) to a shelve file used to save and resume the optimization (see the "save and resume" example in the original Python package's documentation)
number of jobs to run in parallel
acquisition function, one of `"ei"` (expected improvement) or `"ucb"` (upper confidence bound)
`"bayesian"` (Gaussian Process surrogate, the default) or `"mc"`/other methods implemented by the Python package
optional known minimum value of the objective, used for early stopping diagnostics
logical, whether the objective function also returns timing information (see Python package docs)
logical, whether to search on a log scale
path to the Python virtual environment created with `uv` (see the package README for setup instructions)
further named arguments forwarded as-is to `GPopt.GPOpt(...)` on the Python side
A Python `GPopt.GPOpt` object. Useful members (accessed with `$`):
`$optimize(verbose = 1L, n_more_iter = NULL, abs_tol = NULL, ucb_tol = NULL, ...)` runs (or resumes) the optimization loop and returns a `DescribeResult` (an R list with elements `best_params`/`best_score` once it crosses over to R)
`$lazyoptimize(...)` tries several surrogate models automatically
`$x_min`, `$y_min` current best parameters/objective value
`$n_iter` current number of iterations actually run
`$max_ei` history of maximum expected improvement per iteration
`$save(...)`/`$load(path = ...)`/`$close_shelve()` persistence helpers
This function returns the underlying Python object itself (a
GPopt.GPOpt instance, wrapped by reticulate). As with the
`nnetsauce` port, the general rule is: object accesses with `.`'s in
Python are replaced by `$`'s in R. So after building `opt <- GPOpt(...)`,
call `opt$optimize()`, read `opt$x_min`, `opt$y_min`, `opt$n_iter`,
`opt$max_ei`, etc., exactly like you would in Python with `opt.optimize()`,
`opt.x_min`, and so on.
if (FALSE) { # \dontrun{
# Branin function, minimized over [-5, 10] x [0, 15]
branin <- function(x) {
x1 <- x[1]; x2 <- x[2]
term1 <- (x2 - (5.1 * x1^2) / (4 * pi^2) + (5 * x1) / pi - 6)^2
term2 <- 10 * (1 - 1 / (8 * pi)) * cos(x1)
term1 + term2 + 10
}
opt <- GPOpt(
lower_bound = c(-5, 0),
upper_bound = c(10, 15),
objective_func = branin,
n_init = 10,
n_iter = 90,
venv_path = "./venv"
)
res <- opt$optimize(verbose = 2L)
print(opt$x_min)
print(opt$y_min)
} # }