Skip to contents

This function is used as the objective function during model calibration. It simulates a hydrological model over the warm-up and calibration periods and evaluates an error criterion (e.g., KGE) on the calibration period only.

Usage

optim_fn(
  ParamOptim,
  hydro_data,
  split_indices,
  model,
  input,
  snow_module = NULL,
  snow_input,
  snow_parameters = NULL,
  error_crit,
  cal_maximize,
  cal_q_transfo,
  lambda,
  do_transfo_param,
  airGR_RunOptions = NULL,
  airGR_RunOptions_snow_module = NULL
)

Arguments

ParamOptim

A numeric vector of model parameters to be optimized.

hydro_data

A list or data frame containing observed runoff, typically loaded using load_meteo_data.

split_indices

A list of index vectors indicating warm-up and calibration periods, usually from split_data_set.

model

A string specifying the hydrological model. For a complete list see table in vignette("model_overview").

input

A list of model input data, typically created using create_input.

snow_module

Optional. A string specifying the snow module (currently "CemaNeige" and "TUWsnow").

snow_input

Optional. Input data for the snow module.

snow_parameters

Optional. A vector of fixed snow parameters. If NULL, snow parameters are assumed to be part of ParamOptim.

error_crit

A string naming the error criterion function (e.g., "KGE"). Must be compatible with calc_hydroGOF or from the hydroGOF package.

cal_maximize

Logical. If TRUE, the calibration maximizes the objective function.

cal_q_transfo

A string indicating how runoff should be transformed (see transfo_q).

lambda

Optional. A numeric value or vector used for regularization or transformation.

do_transfo_param

Logical. If TRUE, parameters are transformed from the unit hypercube to real-world values before simulation.

airGR_RunOptions

Optional. Run options for airGR models.

airGR_RunOptions_snow_module

Optional. Run options for the snow module if using airGR.

Value

A single numeric value representing the error criterion to be minimized or maximized.

Details

The function handles parameter transformation, snow module simulation, and error handling for cases where the simulated runoff is invalid (e.g., all NAs or zeros).

Note

  • If Qsim is entirely NA, a large penalty value (+/- 1e10) is returned.

  • If Qsim is all zeros and the criterion is KGE, the asymptotic value 1 - sqrt(3) is returned.

  • Qsim is coerced to numeric to ensure compatibility with Qobs, especially for models like TUW.

  • Future improvements may include spatially explicit versions and refined NA handling.

Examples

if (FALSE) {
cal_results <- DEoptim::DEoptim(
  fn = optim_fn,
  lower = lower,
  upper = upper,
  control = DEoptim::DEoptim.control(NP = 50, itermax = 100),
  hydro_data = hydro_data,
  split_indices = split_indices,
  model = "GR4J",
  input = input,
  error_crit = "KGE",
  cal_maximize = TRUE,
  cal_q_transfo = "none",
  do_transfo_param = TRUE
)
}