R/tune.R

Defines functions tune get_tuner_fn

# tune.R
# ::rtemis::
# 2025- EDG rtemis.org

# %% get_tuner_fn ----
#' Get Tuner Function
#'
#' @param type Character: Type of tuner.
#'
#' @author EDG
#'
#' @keywords internal
#' @noRd
get_tuner_fn <- function(type = "GridSearch") {
  type <- match_arg(type, c("GridSearch"))
  switch(type, "GridSearch" = "tune_GridSearch")
} # /rtemis::get_tuner_fn


# %% tune ----
#' Tune Supervised Learning Model
#'
#' @param x tabular data: Training set data.
#' @param hyperparameters `Hyperparameters` object: make using each learner's `setup_*` function.
#' @param tuner_config `TunerConfig` object: created with [setup_GridSearch].
#' @param preprocessor_config Optional `SupervisedPreprocessorConfig` object: created with
#' [setup_SupervisedPreprocessor].
#' @param decomposition_config Optional `DecompositionConfig` object: created with a
#' decomposition `setup_*` function.
#' @param weights Numeric vector: Optional case weights.
#' @param verbosity Integer: Verbosity level.
#' @param seed Optional Integer: Master seed for the grid's RNG substreams.
#' @param shared_memory Character \{"none", "auto", "always"\}: Shared-memory policy for
#' the data sent to workers.
#'
#' @author EDG
#' @keywords internal
#' @noRd
tune <- function(
  x,
  hyperparameters,
  tuner_config,
  preprocessor_config = NULL,
  decomposition_config = NULL,
  weights = NULL,
  verbosity = 1L,
  backend = "none",
  future_plan = "multicore",
  n_workers = 1L,
  seed = NULL,
  shared_memory = "none",
  on_error = "continue"
) {
  check_hyperparameters(hyperparameters)
  check_is_S7(tuner_config, TunerConfig)
  stopifnot(needs_tuning(hyperparameters))

  if (tuner_config@type == "GridSearch") {
    tune_GridSearch(
      x = x,
      hyperparameters = hyperparameters,
      tuner_config = tuner_config,
      preprocessor_config = preprocessor_config,
      decomposition_config = decomposition_config,
      weights = weights,
      verbosity = verbosity,
      backend = backend,
      future_plan = future_plan,
      n_workers = n_workers,
      seed = seed,
      shared_memory = shared_memory,
      on_error = on_error
    )
  } else {
    rtemis.core::abort(
      "Unsupported tuner type: ",
      tuner_config@type,
      class = "rtemis_unsupported_error"
    )
  }
} # /rtemis::tune

Try the rtemis package in your browser

Any scripts or data that you put into this service are public.

rtemis documentation built on Oct. 20, 2026, 1:06 a.m.