fitByOptim {hydromad} | R Documentation |
Fits a hydromad model using R's optim
or nlminb
functions. Has multi-start and pre-sampling options.
fitByOptim(MODEL, objective = hydromad.getOption("objective"), method = hydromad.getOption("optim.method"), control = list(), samples = hydromad.getOption("fit.samples"), sampletype = c("latin.hypercube", "random", "all.combinations"), initpars = NULL, multistart = FALSE, vcov = FALSE, hessian = vcov) fitByOptim1(MODEL, objective = hydromad.getOption("objective"), tol = .Machine$double.eps^0.25)
MODEL |
a model specification created by |
objective |
objective function to maximise, given as a |
method, control |
optimisation algorithm and settings. See |
samples |
number of parameter sets to test. |
sampletype |
sampling scheme – see |
initpars |
initial parameter set. |
multistart |
if this is |
vcov, hessian |
if |
tol |
convergence tolerance, see |
See optim
for a brief description of the available
algorithms, including references to literature.
fitByOptim1
handles a single free parameter using
optimize
; it is called by fitByOptim
, with a
warning, in that case.
the best model from those sampled, according to the given
objective
function. Also, these extra elements are inserted:
fit.result |
the result from |
objective |
the |
funevals |
total number of evaluations of the model simulation function. |
timing |
timing vector as returned by |
Felix Andrews felix@nfrac.org
fitBySampling
,
optim
,
objFunVal
data(Cotter) x <- Cotter[1:1000] ## IHACRES CWI model with power law unit hydrograph modx <- hydromad(x, sma = "cwi", routing = "powuh") modx set.seed(0) foo <- fitByOptim(modx, samples = 100) summary(foo) ## return value from optim (with 'objseq' added): str(foo$fit.result) ## plot objective function value convergence over time xyplot(optimtrace(foo), type = "b", xlab = "function evaluations", ylab = "objective fn. value") ## repeat optimisation with single random starting points fooreps <- replicate(4, fitByOptim(modx, samples = 1, sampletype = "random", objective = hmadstat("r.squared"), method = "Nelder-Mead"), simplify = FALSE) names(fooreps) <- paste("rep.", seq_along(fooreps)) ## extract and plot the optimisation traces traces <- lapply(fooreps, optimtrace) tracesraw <- lapply(fooreps, optimtrace, raw = TRUE) xyplot(do.call("merge", traces), superpose = TRUE, sub = 'method = "Nelder-Mead"', xlab = "Fn. evaluations", ylab = "Objective value", auto.key = list(corner = c(1,0))) + xyplot(do.call("merge", tracesraw), superpose = TRUE, type = "p", cex = 0.5) ## if you try it again with method = "PORT" you will find that all ## replicates converge to the optimum regardless of starting point.