evalPars evaluates a model for a named matrix of parameters.
evalPars(
par.matrix,
object,
objective = hydromad.getOption("objective"),
parallel = hydromad.getOption("parallel")[["evalPars"]]
)Named matrix or data.frame of parameter values, with each row corresponding to a model realisation to evaluate
an object of class hydromad.
the objective function or expression, which can refer to Q
and X. See objFunVal.hydromad
Which parallelisation method to use. Options are
"clusterApply" and "foreach". For any other value, parameters
will be evaluated sequentially. Default is "none". For more
information see hydromad_parallelisation.
evalPars returns a vector of objective function values,
corresponding to the evaluation of each row of par.matrix.
evalPars is used in conjunction with getFreeParsRanges
and the sensitivity package to perform sensitivity analysis. See
demo(sensitivity). Note that the objective function may more
generally return any scalar result, e.g. a scalar prediction calculated only
using X.
Individual model evaluations are generally very fast, so parallelisation is
only really worthwhile when large numbers of evaluations are needed.
"clusterApply" has a slightly lower overhead. "foreach" allows
a broader range of options.
objFunVal.hydromad, parameterSets,
getFreeParsRanges
data(Cotter)
obs <- Cotter[1:1000]
modx <- hydromad(obs,
sma = "cmd", routing = "expuh",
tau_s = c(2, 100), v_s = c(0, 1)
)
## Sample 10 random parameter sets for parameters with defined ranges
pars <- parameterSets(getFreeParsRanges(modx), 10, method = "random")
## Return the default objective function value for each model realisation
evalPars(pars, object = modx)
#> [1] -1.488325 -1.910287 -1.909738 -1.733584 -1.854090 -1.343927 -1.923026
#> [8] -1.597585 -1.295125 -1.866547
## Calculate the 20%ile flow for each model realisation
evalPars(pars, object = modx, objective = ~ quantile(X, 0.2))
#> [1] 4.776152e-05 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00
#> [6] 1.430479e-02 0.000000e+00 0.000000e+00 1.190551e-05 0.000000e+00
## Alternatively, sample 10 random parameter sets from all parameters
## This allows specifying discrete values of parameters
pars <- parameterSets(coef(modx, warn = FALSE), 10, method = "random")