Performs Bayesian Optimization using Optuna to find the best hyperparameters for a single kernel configuration. The search is parallelized by launching multiple R workers (via parallel::makePSOCKcluster) that connect to a shared SQLite database to synchronize trials.

tune_fastsvm_optuna(
  data,
  time_col = "t",
  delta_col = "delta",
  search_space,
  n_trials = 50L,
  cv = 5L,
  cores = parallel::detectCores(),
  seed = NULL,
  verbose = TRUE,
  ...
)

Arguments

data

A data.frame containing the training data.

time_col

Character string. Name of the time column.

delta_col

Character string. Name of the event column (1=event, 0=censored).

search_space

A named list defining the parameters to tune. Use helper functions opt_float, opt_int, or opt_cat.

n_trials

Integer. Total number of trials to run (these are distributed across the cores).

cv

Integer. Number of cross-validation folds to use for evaluating each trial (default 5).

cores

Integer. Number of parallel R workers to launch.

seed

Integer or NULL. Random seed for reproducibility (passed to Optuna's sampler).

verbose

Logical. If TRUE, prints start and end messages.

...

Additional fixed arguments passed to FastKernelSurvivalSVM (e.g., kernel="rbf", max_iter=1000).

Value

An object of class "fastsvm_optuna" containing:

best_params

A list of the optimal hyperparameters found.

best_score

The best mean C-index achieved.

n_trials

The number of trials performed.

study

The original Python Optuna study object.

Examples

if (FALSE) { # \dontrun{
if (reticulate::py_module_available("optuna") && requireNamespace("parallel")) {
  library(FastSurvivalSVM)
  
  # 1. Generate Data
  df <- data_generation(n = 200, prop_cen = 0.3)
  
  # 2. Define Search Space for an RBF Kernel
  #    We want to tune 'alpha' and 'gamma'.
  space <- list(
    alpha = opt_float(0.01, 10, log = TRUE),
    gamma = opt_float(0.001, 1, log = TRUE)
  )
  
  # 3. Run Optimization using ALL available cores
  res <- tune_fastsvm_optuna(
    data         = df,
    time_col     = "tempo",
    delta_col    = "cens",
    search_space = space,
    n_trials     = 20,
    cv           = 3,
    cores        = parallel::detectCores(),
    kernel       = "rbf",
    rank_ratio   = 0.0 # Fixed parameter
  )
  
  print(res$best_params)
  print(res$best_score)

  # 4. Train Final Model with Best Parameters
  #    Using the optimized hyperparameters to fit the model on full data.

  # Combine fixed arguments (kernel, rank_ratio) with tuned ones (alpha, gamma)
  final_args <- c(
    list(
      data       = df,
      time_col   = "tempo",
      delta_col  = "cens",
      kernel     = "rbf",
      rank_ratio = 0.0
    ),
    res$best_params
  )
  
  # Fit using fastsvm()
  final_model <- do.call(fastsvm, final_args)
  
  print(final_model)
}
} # }