This function performs the optimization of a function, possibly in sequential phases of increasing complexity, and it is designed for the calibration of a model, by minimizing the error function fn associated to it.

calibrate(
  par,
  fn,
  gr,
  ...,
  method,
  lower,
  upper,
  phases,
  control,
  hessian,
  replicates,
  parallel
)

# S3 method for default
calibrate(
  par,
  fn,
  gr = NULL,
  ...,
  method = NULL,
  lower = NULL,
  upper = NULL,
  phases = NULL,
  control = list(),
  hessian = FALSE,
  replicates = 1,
  parallel = FALSE
)

Arguments

par

A numeric vector or list. The length of the par argument defines the number of parameters to be estimated (i.e. the dimension of the problem).

fn

The function to be minimized.

gr

A function computing the gradient of fn. If NULL, a numerical approximation of the gradient is used. It can be also a character specifying the method for the computation of the numerical gradient: 'central', 'forward' (the default), 'backward' or 'richardson'.

...

Additional parameters to be passed to fn.

method

The optimization method to be used. The default method is the AHR-ES (Adaptative Hierarchical Recombination Evolutionary Strategy, Oliveros-Ramos & Shin, 2016). See details for the methods available.

lower

Lower threshold value(s) for parameters. One value or a vector of the same length as par. If one value is provided, it is used for all parameters. NA means -Inf. By default -Inf is used (unconstrained).

upper

Upper threshold value(s) for parameters. One value or a vector of the same length as par. If one value is provided, it is used for all parameters. NA means Inf. By default Inf is used (unconstrained).

phases

An optional vector of the same length as par, indicating the phase at which each parameter becomes active. If omitted, default value is 1 for all parameters, performing a single optimization.

control

Parameter for the control of the algorithm itself, see details.

hessian

Logical. Should a numerically differentiated Hessian matrix be returned? Currently not implemented.

replicates

The number of replicates for the evaluation of fn. The default value is 1. A value greater than 1 is only useful for stochastic functions.

parallel

Logical. Use parallel computation numerical of gradient?

Details

In the control list, aggFn is a function to aggregate fn to a scalar value if the returned value is a vector. Some optimization algorithm can exploite the additional information provided by a vectorial output from fn.

See also

Other optimisers: ahres(), optim2(), optimh()

Author

Ricardo Oliveros-Ramos

Examples

calibrate(par=rep(NA, 5), fn=sphereN)
#> Using optimization method 'Rvmmin'.
#> Elapsed time: 0.01s
#> Function value: 0.00272986
#> Parameter values: 2.62e-05 9.95e-06 2.26e-05 -2.52e-06 2.52e-05
#> 
#> Status: Rvmminu appears to have converged
#> Optimization using 'Rvmmin' algorithm.
#> Function value: 0.002729857 
#> Status: Rvmminu appears to have converged 
#> Parameters:
#> [1]  2.615355e-05  9.950590e-06  2.261864e-05 -2.522393e-06  2.519202e-05
#> Computation:
#> function gradient 
#>      166        5 
if (FALSE) {
calibrate(par=rep(NA, 5), fn=sphereN, replicates=3)
calibrate(par=rep(0.5, 5), fn=sphereN, replicates=3, lower=-5, upper=5)
calibrate(par=rep(0.5, 5), fn=sphereN, replicates=3, lower=-5, upper=5, phases=c(1,1,1,2,3))
calibrate(par=rep(0.5, 5), fn=sphereN, replicates=c(1,1,4), lower=-5, upper=5, phases=c(1,1,1,2,3))
}