Skip to contents

Subsample sites, build time-based folds and optimise the mean predictive log-likelihood using `optim` with `L-BFGS-B` bounds.

Usage

tune_hyperparameters_optim(
  obs_data,
  coordinates,
  id_col = "id",
  time_col = "t",
  n_sites_sample = 40,
  K_folds = 5,
  init = c(space = 20, t_per = 4, t_long = 12),
  lower = c(space = 5, t_per = 1, t_long = 3),
  upper = c(space = 200, t_per = 20, t_long = 52),
  period = period,
  seed = 123
)

Arguments

obs_data

Data frame with one row per site-time. Must contain at least `id`, `t`, `y_obs`, `mu_infer` and `f_infer`.

coordinates

Data frame with site-level information including `id`.

id_col

Name of the site identifier column.

time_col

Name of the time column.

n_sites_sample

Number of sites to randomly sample for tuning.

K_folds

Number of cross-validation folds.

init

Initial hyperparameter values.

lower

Lower bounds for hyperparameters.

upper

Upper bounds for hyperparameters.

seed

Random seed for reproducibility.

Value

A list containing the best hyperparameters and optimisation details.

Examples

if (FALSE) { # \dontrun{
init <- c(space = 3, t_per = 4, t_long = 12)
res <- tune_hyperparameters_optim(
  obs_data = obs_data,
  coordinates = coordinates,
  n_sites_sample = 20,
  K_folds = 10,
  init = init,
  lower = c(space = 0.01, t_per = 0.1, t_long = 1),
  upper = c(space = 100, t_per = 100, t_long = 24)
)
res$best_theta
} # }