The Michel's calibration strategy (Calibration_Michel() function) is the calibration algorithm proposed in airGR. However, other optimization methods can be used in combination with airGR. We show here how to use different R packages to perform parameter estimation.

In this vignette, we use the GR4J model to illustrate the different optimization strategies. In particular, we assume that the R global environment contains input climate data, observed discharge and functions from the airGR Get Started vignette, as shown below. Please note that the calibration period is defined in the CreateRunOptions() function .


Regarding the different optimization strategies presented here, we refer to each package for in-depth information about the description of the methods used.

Please note that this vignette is only for illustration purposes and does not provide any guidance about which optimization strategies is recommended for the family of the GR models.

Definition of the necessary function

Parameter estimation can be performed by defining a function that takes a parameter set as input and returns the value of the performance criterion. There are two important steps: the transformation of parameters to real space and the computation of the value of the performance criterion. Here we choose to minimize the root mean square error.

The change of the repository from the “real” parameter space to a “transformed” space ensures homogeneity of displacement in the different dimensions of the parameter space during the step-by-step procedure of the calibration algorithm of the model.

OptimGR4J <- function(Param_Optim) {
  ## Transformation of the parameter set to real space
  Param_Optim_Vre <- airGR::TransfoParam_GR4J(ParamIn = Param_Optim,
                                              Direction = "TR")
  ## Simulation given a parameter set
  OutputsModel <- airGR::RunModel_GR4J(InputsModel = InputsModel,
                                       RunOptions = RunOptions,
                                       Param = Param_Optim_Vre)
  ## Computation of the value of the performance criteria
  OutputsCrit <- airGR::ErrorCrit_RMSE(InputsCrit = InputsCrit,
                                       OutputsModel = OutputsModel,
                                       verbose = FALSE)

In addition, we need to define the lower and upper bounds of the four GR4J parameters in the transformed parameter space:

lowerGR4J <- rep(-9.99, times = 4)
upperGR4J <- rep(+9.99, times = 4)

Local optimization

We start with a local optimization strategy by using the PORT routines (using the nlminb() of the stats package) and by setting a starting point in the transformed parameter space:

startGR4J <- c(4.1, 3.9, -0.9, -8.7)
optPORT <- stats::nlminb(start = startGR4J, 
                         objective = OptimGR4J,
                         lower = lowerGR4J, upper = upperGR4J,
                         control = list(trace = 1))

The RMSE value reaches a local minimum value after 35 iterations.

We can also try a multi-start approach to test the consistency of the local optimization. Here we use the same grid used for the filtering step of the Michel's calibration strategy (Calibration_Michel() function). For each starting point, a local optimization is performed.

startGR4J <- expand.grid(data.frame(CalibOptions$StartParamDistrib))
optPORT_ <- function(x) {
  opt <- stats::nlminb(start = x, 
                       objective = OptimGR4J,
                       lower = lowerGR4J, upper = upperGR4J,
                       control = list(trace = 1))
list_opt <- apply(startGR4J, 1, optPORT_)

We can then extract the best parameter sets and the value of the performance criteria:

list_par <- t(sapply(list_opt, function(x) x$par))
list_obj <- sapply(list_opt, function(x) x$objective)
df_port  <- data.frame(list_par, RMSE = list_obj)

As can be seen below, the optimum performance criterion values (column objective) can differ from the global optimum value in many cases, resulting in various parameter sets.

##        X1              X2               X3                 X4          
##  Min.   :5.548   Min.   :0.1231   Min.   :-0.04074   Min.   :-8.24302  
##  1st Qu.:5.548   1st Qu.:0.1237   1st Qu.:-0.01277   1st Qu.:-8.24302  
##  Median :5.548   Median :0.8843   Median : 4.47923   Median :-8.24302  
##  Mean   :5.685   Mean   :0.6307   Mean   : 2.97879   Mean   :-5.38233  
##  3rd Qu.:5.954   3rd Qu.:0.8843   3rd Qu.: 4.47923   3rd Qu.: 0.01052  
##  Max.   :5.964   Max.   :0.8843   Max.   : 4.47923   Max.   : 0.99606  
##       RMSE       
##  Min.   :0.7852  
##  1st Qu.:0.7852  
##  Median :0.7852  
##  Mean   :0.9338  
##  3rd Qu.:1.2211  
##  Max.   :1.2508

The existence of several local minima illustrates the importance of defining an appropriate starting point or of using a multi-start strategy or a global optimization strategy.

Global optimization

Global optimization is most often used when facing a complex response surface, with multiple local mimina. Here we use the following R implementation of some popular strategies:

Differential Evolution

optDE <- DEoptim::DEoptim(fn = OptimGR4J,
                          lower = lowerGR4J, upper = upperGR4J,
                          control = DEoptim::DEoptim.control(NP = 40, trace = 10))

Particle Swarm

optPSO <- hydroPSO::hydroPSO(fn = OptimGR4J,
                             lower = lowerGR4J, upper = upperGR4J,
                             control = list(write2disk = FALSE, verbose = FALSE))


optMALS <- Rmalschains::malschains(fn = OptimGR4J,
                                   lower = lowerGR4J, upper = upperGR4J, 
                                   maxEvals = 2000)


As it can be seen in the table below, the four additional optimization strategies tested lead to very close optima.

##     Algo      X1    X2     X3    X4
## 1 Michel 257.238 1.012 88.235 2.208
## 2   PORT 256.808 1.004 88.167 2.205
## 3     DE 256.808 1.004 88.167 2.205
## 4    PSO 256.836 1.006 88.207 2.204
## 5  MA-LS 256.808 1.004 88.167 2.205