tune_densemlp: Tune a densemlp model over a hyperparameter grid

View source: R/tuning.R

tune_densemlpR Documentation

Tune a densemlp model over a hyperparameter grid

Description

Fits densemlp() for every combination in grid (each repeated repeats times with successive seeds), ranks candidates by their best internal validation loss, and optionally refits the best configuration on the full data.

Usage

tune_densemlp(
  x,
  y,
  task = c("auto", "regression", "binary", "multiclass", "survival", "count"),
  grid = NULL,
  validation = 0.2,
  seed = 1L,
  repeats = 3L,
  ncores = 1L,
  verbose = FALSE,
  refit = TRUE,
  weights = NULL
)

Arguments

x

Predictor data.frame or matrix.

y

Outcome vector.

task

"auto" infers the task from y, as in densemlp().

grid

A named list of candidate values. Supported names: hidden_units (a list of integer vectors), dropout (a list of numeric vectors, recycled to hidden_units length), residual, gated, ema_decay, lr_schedule, epochs, batch_size, lr. Any name omitted falls back to a single-value default. interaction is intentionally not tunable here: it is numerically unstable on small/wide data (see package NEWS) and is left at FALSE.

validation

Validation fraction used for every candidate fit.

seed

Base random seed.

repeats

Number of repeated seeds per candidate.

ncores

Number of cores used to fit candidates in parallel (see densemlp()'s ncores).

verbose

Print per-candidate progress.

refit

Refit the best configuration on the supplied data.

weights

Optional non-negative case weights, one per row, passed to every densemlp() fit; candidates are then ranked by the weighted validation loss.

Value

A list of class densemlp_tuned with results (one row per candidate, ranked best first by mean validation loss), best_config, and, when refit = TRUE, best_fit.

Examples

set.seed(1)
x <- data.frame(a = rnorm(80), b = rnorm(80))
y <- x$a - 0.5 * x$b + rnorm(80, sd = 0.1)
tuned <- tune_densemlp(
  x, y, repeats = 1,
  grid = list(hidden_units = list(c(8), c(16, 8)), epochs = c(20))
)
tuned$best_config

densemlp documentation built on Nov. 3, 2026, 1:09 a.m.