Type: | Package |
Title: | Multi-Objective Optimisation with Focus on Environmental Models |
Version: | 0.1-14 |
Author: | Rodrigo Marinao-Rivas [aut, cre, cph],
Mauricio Zambrano-Bigiarini
|
Maintainer: | Rodrigo Marinao-Rivas <ra.marinao.rivas@gmail.com> |
Description: | State-of-the-art Multi-Objective Particle Swarm Optimiser (MOPSO), based on the algorithm developed by Lin et al. (2018) <doi:10.1109/TEVC.2016.2631279> with improvements described by Marinao-Rivas & Zambrano-Bigiarini (2020) <doi:10.1109/LA-CCI48322.2021.9769844>. This package is inspired by and closely follows the philosophy of the single objective 'hydroPSO' R package ((Zambrano-Bigiarini & Rojas, 2013) <doi:10.1016/j.envsoft.2013.01.004>), and can be used for global optimisation of non-smooth and non-linear R functions and R-base models (e.g., 'TUWmodel', 'GR4J', 'GR6J'). However, the main focus of 'hydroMOPSO' is optimising environmental and other real-world models that need to be run from the system console (e.g., 'SWAT+'). 'hydroMOPSO' communicates with the model to be optimised through its input and output files, without requiring modifying its source code. Thanks to its flexible design and the availability of several fine-tuning options, 'hydroMOPSO' can tackle a wide range of multi-objective optimisation problems (e.g., multi-objective functions, multiple model variables, multiple periods). Finally, 'hydroMOPSO' is designed to run on multi-core machines or network clusters, to alleviate the computational burden of complex models with long execution time. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Depends: | R (≥ 4.0.0) |
Imports: | zoo, parallel, randtoolbox, lhs, hydroTSM, methods |
Suggests: | knitr, rmarkdown, smoof, hydroGOF, airGR, TUWmodel |
URL: | https://gitlab.com/rmarinao/hydroMOPSO |
BugReports: | https://gitlab.com/rmarinao/hydroMOPSO/-/issues |
LazyLoad: | yes |
ByteCompile: | TRUE |
NeedsCompilation: | no |
Repository: | CRAN |
Packaged: | 2025-06-16 19:23:44 UTC; rmarinao |
Date/Publication: | 2025-06-18 08:10:02 UTC |
Multi-Objective Calibration of Hydrological Models using MOPSO
Description
State-of-the-art Multi-Objective Particle Swarm Optimiser (MOPSO), based on the NMPSO algorithm developed by Lin et al. (2018), which in turn is based on the work by Coello and Lechuga (2002) and Kennedy and Eberhart (1995). To maintain diversity and accelerate convergence to the Pareto-optimal front (POF), NMPSO combines two search mechanism (Lin et al., 2015), these being a PSO search and the application of genetic operators. Lin et al. (2015) also included a balanceable fitness estimation (BFE) procedure to rank particles in a external archive (A), in order to provide an effective guidance to the true POF, while keeping diversity among particles. hydroMOPSO
is developed with a focus on solving multi-objective problems with the least amount of function/model evaluations, taking the work done by Marinao-Rivas and Zambrano-Bigiarini (2021), who provided a default configuration of: i) the swarm size, ii) the maximum number of particles in the external archive, and iii) the maximum amount of genetic operations in the external archive.
This package and the attached tutorials have been developed with a special focus on the calibration of hydrological/environmental models and related real-world problems, but it can also be used for the calibration of any type of model that can be run from the command-line or the optimisation of certain functions to be defined by the user in the R environment.
For calibration problems, hydroMOPSO
is model-independent, allowing the user to easily interface any computer simulation model with the calibration engine (NMPSO). Thus, the user only needs to indicate which model parameters will be modified and where, how and where to run the hydrological model, either in the R environment or from the system console; and finally how to read the model results. With these aspects properly structured by the user, the algorithm it will take control over the model to be calibrated until a maximum number of iterations is reached.
Adittionally, this package provides intuitive plot summaries and detailed information about optimisation performance. These features make it easier to interpret and assess the multi-objective calibration results, particularly for non-experts. The package offers a comprehensive set of tools that streamline the calibration process, from model parameter estimation to result analysis. With these features, users can quickly identify the best-performing models and gain deeper insights into the underlying processes and mechanisms of hydrological systems.
The operating mechanism of hydroMOPSO
is based on the hydroPSO
R package developed by Zambrano-Bigiarini and Rojas (2013), inheriting the philosophy of flexibility that allows dealing with any calibration problem with different fine-tuning options, as well as taking advantage of multicore machines or network clusters to alleviate the computational burden of complex models with long execution time.
Details
Package: | hydroMOPSO |
Type: | Package |
Version: | 0.1-3 |
Date: | 2023-04-24 |
License: | GPL (>=2) |
LazyLoad: | yes |
Packaged: | 2023-04-24; rmarinao |
BuiltUnder: | R version 4.3.0 (2023-04-21) -- "Already Tomorrow"; x86_64-pc-linux-gnu (64-bit) |
Author(s)
Rodrigo Marinao-Rivas and Mauricio Zambrano-Bigiarini
Maintainer: Rodrigo Marinao-Rivas <ra.marinao.rivas@gmail.com>
References
Coello, C. A. C., & Lechuga, M. S. (2002). MOPSO: A proposal for multiple objective particle swarm optimization. Proceedings of the 2002 Congress on Evolutionary Computation, CEC 2002, 2, 1051-1056. doi:10.1109/CEC.2002.1004388
Kennedy, J., & Eberhart, R. (1995). Particle swarm optimization. Proceedings of ICNN95 - International Conference on Neural Networks, 4, 1942-1948. doi:10.1109/ICNN.1995.488968
Lin, Q., Li, J., Du, Z., Chen, J., & Ming, Z. (2015). A novel multi-objective particle swarm optimization with multiple search strategies. European Journal of Operational Research, 247, 732-744. doi:10.1016/J.EJOR.2015.06.071
Lin, Q., Liu, S., Zhu, Q., Tang, C., Song, R., Chen, J., ... Zhang, J. (2016). Particle Swarm Optimization With a Balanceable Fitness Estimation for Many-Objective Optimization Problems. IEEE Transactions on Evolutionary Computation, 22, 32-46. doi:10.1109/TEVC.2016.2631279
Marinao-Rivas, R., & Zambrano-Bigiarini, M. (2021). Towards best default configuration settings for NMPSO in multi-objective optimization. 2021 IEEE Latin American Conference on Computational Intelligence, LA-CCI 2021. doi:10.1109/LA-CCI48322.2021.9769844
Zambrano-Bigiarini, M., & Rojas, R. (2013). A model-independent Particle Swarm Optimisation software for model calibration. Environmental Modelling & Software, 43, 5-25. doi:10.1016/j.envsoft.2013.01.004
See Also
https://CRAN.R-project.org/package=hydroPSO
https://CRAN.R-project.org/package=hydroGOF
https://CRAN.R-project.org/package=hydroTSM
Example wrapper functions to execute GR4J model
Description
Example wrapper functions to execute the GR4J model and obtain the performance of two objective functions (KGE2012 and KGEGarcia), in a calibration (GR4JExampleCal
) or a verification period (GR4JExampleVer
). Keep in mind that, within hydroMOPSO
, the calibration or verification wrapper functions essentially have to be prepared by the user, with the objective functions that are convenient and the output variables that are necessary.
Thus, the functions presented here are only intended to work with examples from the documentation and serve as a guide to:
1) The general scheme of the calibration/verification wrapper functions
2) The assimilation of mandatory inputs
3) The assimilation of mandatory outputs
Usage
GR4JExampleCal(param.values,
Obs,
Objs.names,
var.names,
var.units,
full.period,
warmup.period,
cal.period,
InputsModel,
RunOptions,
area)
GR4JExampleVer(param.values,
Obs,
Objs.names,
var.names,
var.units,
full.period,
warmup.period,
cal.period,
InputsModel,
RunOptions,
area)
Arguments
param.values |
( |
Obs |
( |
Objs.names |
( |
var.names |
( |
var.units |
( |
full.period |
( |
warmup.period |
( |
cal.period |
( |
InputsModel |
( |
RunOptions |
( |
area |
( |
Value
(list
)
The returned list contains two elements
- Objs
(
numeric
)
Vector with the numerical values of the objectives (GoF1 and GoF2).- sim
(
list
)
List with as many elements as time series of the output variables of the model (in this case only one output variable: streamflows).
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
hydroMOPSO
Comparison between observed and simulated variables
Description
Simple comparison between time series of observed and simulated variables. This function is specially designed to check the correct operation of the wrapper functions prepared by the user. The premise is as follows: if the user can generate a 'nice' graph (graphically evidencing the simulated and observed values, and obtaining finite numerical values for the objectives) then they can proceed with greater confidence to the hydroMOPSO optimisation step.
Usage
SimVsObs(sim,
obs,
obj.values,
obj.names,
var.names,
var.units,
legend.sim = "Simulated",
legend.obs = "Observed",
cal.period,
warmup.period,
full.period,
xlim = NULL,
ylim = NULL,
main = "study case #1",
analysis.period,
digits.round = 8,
col.obs = "black",
col.sim = "mediumblue",
lwd = 0.75,
pch.obs = 15,
cex.pt = 0.25,
cex.main = 1,
cex.lab = 1,
cex.axis = 1,
cex.leg = 1)
Arguments
sim |
( |
obs |
( |
obj.values |
( |
obj.names |
( |
var.names |
( |
var.units |
( |
legend.sim |
( |
legend.obs |
( |
warmup.period |
( |
cal.period |
( |
full.period |
( |
xlim |
( |
ylim |
( |
main |
( |
analysis.period |
( |
digits.round |
( |
col.obs |
( |
col.sim |
( |
lwd |
( |
pch.obs |
( |
cex.pt |
( |
cex.main |
( |
cex.lab |
( |
cex.axis |
( |
cex.leg |
( |
Value
No return value
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
hydroMOPSO
Examples
###############################################################################################
# This example is derived from example 5 of the hydroMOPSO function
library(hydroMOPSO)
library(airGR)
library(hydroTSM)
library(hydroGOF)
# RTL basin ------------------------------------------------
basin.area <- 1415025887 # basin area in square meters
# Load time series -----------------------------------------
data(Trancura9414001plus) # Load RTL data set
# Dates ----------------------------------------------------
dates.raw <- Trancura9414001plus[,"Date"]
dates <- as.Date(dates.raw) # dates
# INPUTS time series ---------------------------------------
# Precipitation (input variable)
ts.pcp.raw <- Trancura9414001plus[,"P_mm"]
ts.pcp <- zoo(ts.pcp.raw, dates)
# Potential EvapoTranspiration (input variable)
ts.pet.raw <- Trancura9414001plus[,"PET_mm"]
ts.pet <- zoo(ts.pet.raw, dates)
# OUTPUTS time series --------------------------------------
# Observed streamflow (calibration output variable)
ts.qobs.raw <- Trancura9414001plus[,"Qobs_m3s"]
ts.qobs <- zoo(ts.qobs.raw, dates)
# Parameter ranges and noCal parameters --------------------
lower <- c("X1" = 0.01, "X2" = -100, "X3" = 0.01, "X4" = 0.5) # parameter range lower threshold
upper <- c("X1" = 1200, "X3" = 100, "X3" = 5000, "X4" = 5 ) # parameter range upper threshold
noCal.param <- (lower + upper)/2 # uncalibrated parameters
# Names and units of observed output variables -------------
char.obs.names <- "Streamflow"
char.obs.units <- "m3/s"
# Objectives names -----------------------------------------
char.objs.names <- c("KGE2012_Q", "KGEGarcia_Q")
# Calibration dates and subsetting -------------------------
WarmUpCal.dates <- dip("1979-01-01", "1979-12-31") # WarmUp for Calibration
Cal.dates <- dip("1980-01-01", "1999-12-31") # Calibration
FullCal.dates <- dip("1979-01-01", "1999-12-31") # WarmUp + Calibration
start.FullCal <- FullCal.dates[1]
end.FullCal <- FullCal.dates[length(FullCal.dates)]
# INPUTS time series ---------------------------------------
# Precipitation (input variable)
ts.pcp.FullCal <- window(ts.pcp, start = start.FullCal, end = end.FullCal) # subsetting pcp
# Potential EvapoTranspiration (input variable)
ts.pet.FullCal <- window(ts.pet, start = start.FullCal, end = end.FullCal) # subsetting pet
# OUTPUTS time series --------------------------------------
# Observed streamflow (calibration output variable)
ts.qobs.FullCal <- window(ts.qobs, start = start.FullCal, end = end.FullCal) # subsetting qobs
list.obs.Cal <- list(Q = ts.qobs.FullCal)
# Structuring Inputs and Options of GR4J model -------------
InputsModel.Cal <- CreateInputsModel(FUN_MOD= RunModel_GR4J,
DatesR= as.POSIXlt(FullCal.dates),
Precip= coredata(ts.pcp.FullCal),
PotEvap= coredata(ts.pet.FullCal))
RunOptions.Cal <- CreateRunOptions(FUN_MOD= RunModel_GR4J, InputsModel= InputsModel.Cal,
IndPeriod_Run = 1:length(FullCal.dates), warnings = FALSE)
# Checking Wrapper function in calibration -----------------
noCal.results.Cal <- GR4JExampleCal(param.values = noCal.param,
Obs = list.obs.Cal,
Objs.names = char.objs.names,
var.names = char.obs.names,
var.units = char.obs.units,
warmup.period = WarmUpCal.dates,
cal.period = Cal.dates,
full.period = FullCal.dates,
InputsModel = InputsModel.Cal,
RunOptions = RunOptions.Cal,
area = basin.area)
noCal.sim.Cal <- noCal.results.Cal[["sim"]]
noCal.objs.Cal <- noCal.results.Cal[["Objs"]]
dev.new()
SimVsObs(sim = noCal.sim.Cal, obs = list.obs.Cal,
obj.values = noCal.objs.Cal, obj.names = char.objs.names,
var.names = char.obs.names, var.units = char.obs.units,
legend.sim = "Simulated", legend.obs = "Observed",
warmup.period = WarmUpCal.dates, cal.period = Cal.dates, full.period = FullCal.dates,
main = "...just checking GR4JExampleCal function", analysis.period = "calibration",
digits.round = 4)
Straightforward modification of a value in input text file
Description
This function provides the capability to modify input text files directly within the R environment, requering only minimal instructions. It was conceived to facilitate users to execute the calibration procedure via hydroMOPSO()
, while staying entirely within the R environment. Thus, it precludes the need for manually editing text files, eliminating undesirable coordination that could potentially lead to errors.
Usage
SpecificValueInFile(modlist)
Arguments
modlist |
( |
Details
The modlist
argument is a list with an indeterminate number of objects, which only depends on the number of modifications the user needs to make, for example, being something like modlist=list(mod_1, mod_2, mod_3,mod_4)
. Each of the ‘mod
’ objects in this list must provide the following items:
- ParamID
(
character
)
The ID of the parameter to be modified.- newvalue
(
numeric
)
Numeric value to be written into the text file.- filename
(
character
)
Name of the text file that will be modified.- row
(
numeric
)
Row number infilename
wherenewvalue
will be written.- col.ini
(
numeric
)
Starting column number infilename
wherenewvalue
is going to be written.- col.fin
(
numeric
)
Ending column number infilename
wherenewvalue
is going to be written.- decimals
(
numeric
)
Number of decimal places used to writenewvalue
intofilename
.
Value
No return value
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
Hydrometeorological time series for Trancura antes de Llafenco River Basin
Description
Daily time series of precipitation, air temperature (max, min, mean), potential evapotranspiration and streamflows for the catchment draining into the 'Trancura antes de Llafenco' streamflow station (Cod.BNA: 9414001, drainage area= 1416 km2), Araucania Region, Chile (Lat:-39.3333, Lon:-71.6667), with data from 01/Jan/1979 to 31/Dec/2020 (including some gaps in streamflow data).
Usage
data(Trancura9414001plus)
Format
zoo with seven columns:
-) Dates: character with the date (YYYY-MM-DD) for each daily observation.
-) Pp_mm: Spatially-averaged mean daily values of precipitation computed based on the CR2met dataset, [mm/day].
-) Tmax_degC: Spatially-averaged mean daily values of maximum air temperature computed based on the CR2met dataset, [degree Celsius].
-) Tmin_degC: Spatially-averaged mean daily values of minimum air temperature computed based on the CR2met dataset, [degree Celsius].
-) Tmean_degC: Spatially-averaged mean daily values of mean air temperature computed based on the CR2met dataset, [degree Celsius].
-) PET_mm: Spatially-averaged mean daily values of potential evapotranspiration (PET), computed with the Hargreaves-Samani equation based on daily maximum and minimum air temperatures obtained from the CR2met dataset, [mm/day].
-) Qobs_m3s: Daily streamflows measured at the Trancura antes de Llafenco (9414001) station.
-) ETobs_mm: Daily evapotranspiration (ET) estimated at the Trancura antes de Llafenco (9414001) with the 8-day evapotranspiration product PML v2 (Zhang, 2019). The 8-day time series are disaggregated on a daily scale just dividing by 8, so, it is recommended to use this information on a weekly, monthly or annual scale.
Source
CR2met v2 is a gridded product of observed daily precipitation an maximum/minimim temperature, covering the period 1979-01-01 to 2020-12-31. Its developed by Boisier et al. (2018) and provided by Center for Climate and Resilience Research, Universidad de Chile, Santiago, Chile (https://zenodo.org/records/7529682, last accessed [Dic 2023]).
PML v2 is a gridded product of estimated 8-day evapotranspiration, covering the period 2020-03-01 to 2020-04-30. The proper use of this information as "observed values" can be a subject of discussion, however, they are included in hydroMOPSO
for mere didactic purposes, hoping that future research will provide more reliable information to use as ET observations.
These data are intended to be used for research purposes only, being distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY.
References
Boisier, J. P., Alvarez-Garreton, C., Cepeda, J., Osses, A., Vasquez, N., and Rondanelli, R. (2018). CR2MET: A high-resolution precipitation and temperature dataset for hydroclimatic research in Chile. EGUGA, 20, 19739. Opgehaal van https://ui.adsabs.harvard.edu/abs/2018EGUGA..2019739B/abstract
Zhang, Y., Kong, D., Gan, R., Chiew, F. H. S., McVicar, T. R., Zhang, Q., & Yang, Y. (2019). Coupled estimation of 500 m and 8-day resolution global evapotranspiration and gross primary production in 2002-2017. Remote Sensing of Environment, 222, 165-182. doi:10.1016/J.RSE.2018.12.031
Multi-Objective Particle Swarm Optimisation algorithm (NMPSO)
Description
Multi-objective Particle Swarm Optimisation algorithm (NMPSO). The default configuration of hydroMOPSO has been adapted to obtain results with the fewest number of iterations possible.
Important: In Example 5 (calibration of GR4J hydrological model), maxit = 50
was set just for practical needs when testing the package. For acceptable results please change to maxit = 250
. With any more robust model and with up to 12 parameters we recommend maxit = 1000
.
Usage
hydroMOPSO(fn='hydromod',
lower=-Inf,
upper=Inf,
control=list(),
model.FUN=NULL,
model.FUN.args=list(),
BC.space.norm = FALSE,
obj.thr = NULL,
...)
Arguments
fn |
( When |
lower |
( |
upper |
( |
control |
( |
model.FUN |
( |
model.FUN.args |
( |
BC.space.norm |
( |
obj.thr |
( |
... |
further arguments to be passed to |
Details
By default, hydroMOPSO performs minimisation on all objectives specified in fn
(MinMax='min'
in control
list), but this can be changed to maximisation (MinMax='max'
in control
list). If in fn
you have to maximise some objectives and minimise others, you must make them all point to the same direction (all maximising or all minimising), which can be handled simply with a sign (See Example 2 where this type of case is presented).
Although the NMPSO algorithm was formulated to deal with many objectives, the default definitions in hydroMOPSO
, and therefore the applications made in research linked to this package, have been made with a focus on two and three objectives. Extending applications to optimisations with four or more objectives is possible with this package (so you are welcome to formulate such problems and solve them with hydroMOPSO
!), but be very careful in analyzing your results.
The control
argument is a list that can supply any of the following components:
- drty.in
(
character
)
(OPTIONAL) Used only whenfn='hydromod'
Name of the directory storing the input files required for PSO, i.e. ‘ParamRanges.txt’ and ‘ParamFiles.txt’.- drty.out
(
character
)
Path to the directory storing the output files generated by hydroMOPSO.- param.ranges
(
character
)
(OPTIONAL) Used only whenfn=='hydromod' | fn=='hydromodInR'
Name of the file defining the minimum and maximum boundary values for each one of the parameters to be optimisated with NMPSO.- digits
(
numeric
)
(OPTIONAL) Used only whenwrite2disk=TRUE
Number of significant digits used for writing the output files with scientific notation.- digits.dom
(
numeric
)
number of decimal places used in dominance check. Fewer decimal places (say, 16, 8, or 4, for example) may be necessary to prevent the algorithm from resulting in solutions that are nearly the same.
By defaultdigits.dom=Inf
, which basically means numbers are not rounded- MinMax
(
character
)
Indicates whether a maximisation or minimisation multi-objetive problem needs to be solved. Valid values are in:c('min', 'max')
. By defaultMinMax='min'
. Thiscontrol
argument applies to all objective functions at the same time, so they must all go in the same direction (either all maximizing or all minimizing; keep in mind that for a particular function to go from maximizing to minimizing, or vice versa, it is only necessary add a minus sign (-)).- npart
(
numeric
)
Number of particles in the swarm. By defaultnpart=10
, inherited from R-packagehydroMOPSO
.- maxrep
(
numeric
)
Maximum number of particles to be stored in the updated Pareto Front in each iteration.
By defaultmaxrep=100
- maxcross
(
numeric
)
Maximum number of Pareto Front particles that, for each iteration, perform the crossing and mutatiom in the application of genetic operators.
By defaultmaxcross=50
- maxit
(
numeric
)
Maximum number of iterations.
By defaultmaxit=1000
- Xini.type
(
character
)
Indicates how to initialise the particles' positions in the swarm within the ranges defined bylower
andupper
.
Valid values are:
-) Sobol: Sobol initialisation of positions, usingnpart
number of samples contained in parameter space bounded bylower
andupper
. It requires the randtoolbox package
-) lhs: Latin Hypercube initialisation of positions, usingnpart
number of strata to divide each parameter range. It requires the lhs package
-) random: random initialisation of positions withinlower
andupper
By defaultXini.type='Sobol'
- Vini.type
(
character
)
Indicates how to initialise the particles' velocities in the swarm.
Valid values are:
-) zero: all the particles are initialised with zero velocity
-) random2011: random initialisation of velocities withinlower-Xini
andupper-Xini
, as defined in SPSO 2011 (‘Vini=U(lower-Xini, upper-Xini)’) (see Clerc, 2012, 2010)
-) lhs2011: same as in random2011, but using a Latin Hypercube initialisation withnpart
number of strata instead of a random uniform distribution for each parameter. It requires the lhs package
-) random2007: random initialisation of velocities withinlower
andupper
using the ‘half-diff’ method defined in SPSO 2007 (‘Vini=[U(lower, upper)-Xini]/2’) (see Clerc, 2012, 2010)
-) lhs2007: same as in random2007, but using a Latin Hypercube initialisation withnpart
number of strata instead of a random uniform distribution for each parameter. It requires the lhs package
By defaultVini.type='zero'
- boundary.wall
(
character
)
Indicates the type of boundary condition to be applied during optimisation.
Valid values are: absorbing2011, absorbing2007, reflecting, damping, invisible
By defaultboundary.wall='absorbing2011'
Experience has shown that Clerc's constriction factor and the inertia weights do not always confine the particles within the solution space. To address this problem, Robinson and Rahmat-Samii (2004) and Huang and Mohan (2005) propose different boundary conditions, namely, reflecting, damping, absorbing and invisible to define how particles are treated when reaching the boundary of the searching space (see Robinson and Rahmat-Samii (2004) and Huang and Mohan (2005) for further details).- cal.hv
(
logical
)
(OPTIONAL)
Indicates whether or not the hypervolume formed between the hyperplane of the Pareto Front and a nadir point designated asnadir.point
will be calculated.
By defaultcal.hv=FALSE
- nadir.point
(
numeric
)
(OPTIONAL) Only required whencal.hv=TRUE
Nadir point from which the hypervolume will be calculated in each iteration step. It should correspond to a reference point considered as the worst acceptable optimal value.- n.samples
(
integer
)
(OPTIONAL) Only required whencal.hv=TRUE
Number of points to estimate hypervolume, based on MonteCarlo sampling.
By defaultn.samples=10000
- write2disk
(
logical
)
Indicates if the output files will be written to the disk.
By defaultwrite2disk=TRUE
- verbose
(
logical
)
Indicates if progress messages are to be printed.
By defaultverbose=TRUE
- plot
(
logical
)
Indicates if a plot with the Pareto Front will be drawn after each iteration.
By defaultplot=FALSE
- REPORT
(
integer
)
(OPTIONAL) Used only whenverbose=TRUE
The frequency of report messages printed to the screen.
By defaultREPORT=10
- parallel
(
character
)
Indicates how to parallelise ‘hydroMOPSO’ (to be precise, only the evaluation of the objective functionfn
is parallelised). Valid values are:
-)none: no parallelisation is made (this is the default value)
-)parallel: parallel computations for network clusters or machines with multiple cores or CPUs. A ‘FORK’ cluster is created with themakeForkCluster
function. Whenfn.name='hydromod'
the evaluation of the objective functionfn
is done with theclusterApply
function of the parallel package. Whenfn.name != 'hydromod'
the evaluation of the objective functionfn
is done with theparRapply
function of the parallel package.
-)parallelWin: parallel computations for network clusters or machines with multiple cores or CPUs (this is the only parallel implementation that works on Windows machines). A ‘PSOCK’ cluster is created with themakeCluster
function. Whenfn.name='hydromod'
the evaluation of the objective functionfn
is done with theclusterApply
function of the parallel package. Whenfn.name != 'hydromod'
the evaluation of the objective functionfn
is done with theparRapply
function of the parallel package.- par.nnodes
(
numeric
)
(OPTIONAL) Used only whenparallel!='none'
Indicates the number of cores/CPUs to be used in the local multi-core machine, or the number of nodes to be used in the network cluster.
By defaultpar.nnodes
is set to the amount of cores detected by the functiondetectCores()
(parallel package)- par.pkgs
(
character
)
(OPTIONAL) Used only whenparallel='parallelWin'
List of package names (as characters) that need to be loaded on each node for allowing the objective functionfn
to be evaluated.
Value
(list
)
The returned list contains elements that vary according to the input specifications
- Rep
(
list
)
Particle repository for the last iteration (just second last phase of NMPSO), detailing:
- Position (
matrix
)
Positions of each set of Pareto Front particles until the last iteration.
- Objs (matrix
)
Objective values of each set of Pareto Front particles until the last iteration.
- BFE (numeric
)
Balanceable Fitness Estimation (BFE) of each set of Pareto Front particles until the last iteration.
- Ranking.BFE (matrix
)
Ranking of each set of Pareto Front particles until the last iteration, according to the BFE value.
- MOPSOResults
(
list
)
Particle repository history of all iterations (both phases of NMPSO), detailing:
- ParetoFront (
data.frame
)
History of objectives values of each Pareto Front particles in all iterations (both phases). In thisdata.frame
, the first column indicates the iterationIter
; the second column the phasePhase
(1 or 2); and the following columns are as many as objectives treated, being identified with the assigned name.
- Particles_ParetoFront (data.frame
)
History of positions of each Pareto Front particles in all iterations (both phases). In thisdata.frame
, the first column indicates the iterationIter
; the second column the phasePhase
(1 or 2); then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- MaxMin (data.frame
)
Specification on whether the objectives are maximised or minimised.
- ObjsNames (data.frame
)
Name of each of the objectives (Obj1, Obj2, ...
).
- hydroDetails
(
list
)
(ONLY ADDED WHENfn=='hydromod' | fn=='hydromodInR'
)
Details about the modeling involved in optimisation:
- Dimensions (
data.frame
)
Number of objectives and number of output variables involved in the optimisation.
- NamesAndUnitsVars (data.frame
)
Name and unit of measure of the output variables involved in the optimisation (var1, var1_unit, var2, var2_unit, ...
).
- Obs (list
)
Observed values of each of the variables involved in the optimisation, keeping in mind that the same format indicated as mandatory input dataObs
within theFUN
function is maintained.
- WarmUp (data.frame
)
Time series indicating the warm-up period used in the optimisation.
- DatesCal (data.frame
)
Time series indicating the calibration period used in the optimisation.
- hydroResults
(
list
)
(ONLY ADDED WHENfn=='hydromod' | fn=='hydromodInR'
)
Post-processed results about the modeling involved in optimisation:
- ParticlesFull (
data.frame
)
History of positions of each Pareto Front particles in all iterations. In thisdata.frame
, the first column indicates the simulation numberSim
, in ascending order from the first simulation (first iteration, phase 1) to the last simulation (last iteration, phase 2); then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- FilledPOF (data.frame
)
Filled Pareto front, built from evaluating the dominance of the solutions of all the iterations performed in the optimisation. To prevent the filled Pareto Front from having too many solutions, the parameters and objective values are rounded according to inputDigitsDom
(number of decimal places). In thisdata.frame
, the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name.
- ParticlesFilledPOF (data.frame
)
Perticles from filled Pareto Front. In thisdata.frame
, the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- ModelOut (list
)
Time series of the model output variables, for all solutions of the filled Pareto Front. This list has as many objects as output variables, and each one corresponds to an object of class zoo with as many columns as solutions of the filled Pareto Front.
- ParticleBestCS (data.frame
)
Best compromise solution, i.e., the solution with the minimum Euclidean distance from the maximum values of each objective. data.frame with only one row and several columns: the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- ModelOutBestCS (list
)
Time series of the model output variables, just for the best compromise solution. This list has as many objects as output variables, and each one corresponds to an object of class zoo with a single time serie.
- ParticleBestObjs (list
)
Solutions that minimise/maximise each of the objectives. data.frame with only one row. In a first level, this list has as many objects as objectives involves in the optimisation, each one with a data.frame with only one row and several columns: the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- ModelOutBestObjs (list
)
Time series of the model output variables, for the maximisation/minimisation of each objective. In a first level, this list has as many objects as objectives involves in the optimisation and, in a second level, each one corresponds to a list with as many objects as output variables, each one corresponding to an object of class zoo with a single time serie.
- AnalysisPeriod (character
)
String indicating the analysis period, in this case"calibration"
.
- DigitsDom (numeric
)
Number of decimal places used in dominance check. Fewer decimal places (say, 16, 8, or 4, for example) may be necessary to prevent the algorithm from resulting in solutions that are nearly the same.
- ObjsNames (data.frame
)
Name of each of the objectives (Obj1, Obj2, ...
).
- MaxMin (data.frame
)
Specification on whether the objectives are maximised or minimised, must be inc("max", "min")
.
- Obs (list
)
Observed values of each of the variables involved in the optimisation, keeping in mind that the same format indicated as mandatory input dataObs
within theFUN
function is maintained.
- Dimensions (data.frame
)
Number of objectives and number of output variables involved in the optimisation.
- NamesAndUnitsVars (data.frame
)
Name and unit of measure of the output variables involved in the optimisation (var1, var1_unit, var2, var2_unit, ...
).
- WarmUp (data.frame
)
Time series indicating the warm-up period used in the optimisation.
- DatesCal (data.frame
)
Time series indicating the calibration period used in the optimisation.
Note
1) For a better understanding of the application cases in which fn=='hydromod' | fn=='hydromodInR'
, it is strongly recommended to review the complementary tutorials to this package.
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini mzb.devel@gmail.com
References
Lin, Q., Liu, S., Zhu, Q., Tang, C., Song, R., Chen, J., Coello, C. A. C., Wong, K.-C., & Zhang, J. (2018). Particle Swarm Optimization With a Balanceable Fitness Estimation for Many-Objective Optimization Problems. IEEE Transactions on Evolutionary Computation, 22(1), 32-46. doi:10.1109/TEVC.2016.2631279
Marinao-Rivas, R., & Zambrano-Bigiarini, M. (2021). Towards best default configuration settings for NMPSO in Multiobjective Optimization. 2021 IEEE Latin American Conference on Computational Intelligence. (Accepted).
Zambrano-Bigiarini, M.; R. Rojas (2013), A model-independent Particle Swarm Optimization software for model calibration, Environmental Modelling & Software, 43, 5-25, doi:10.1016/j.envsoft.2013.01.004
Coello, C. A. C., & Lechuga, M. S. (2002). MOPSO: A proposal for multiple objective particle swarm optimization. Proceedings of the 2002 Congress on Evolutionary Computation, CEC 2002, 2, 1051-1056. doi:10.1109/CEC.2002.1004388
Kennedy, J., & Eberhart, R. (1995). Particle swarm optimization. Proceedings of ICNN'95 - International Conference on Neural Networks, 4, 1942-1948. doi:10.1109/ICNN.1995.488968
Deb, K. (1999). Multi-objective genetic algorithms: problem difficulties and construction of test problems. Evolutionary computation, 7, 205-230. doi:10.1162/EVCO.1999.7.3.205
Kursawe, F. (1991). A variant of evolution strategies for vector optimization. Lecture Notes in Computer Science (including subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics), 496 LNCS, 193-197. doi:10.1007/BFB0029752
Deb, K., Thiele, L., Laumanns, M., & Zitzler, E. (2005). Scalable Test Problems for Evolutionary Multiobjective Optimization (bll 105-145; A. Abraham, L. Jain, & R. Goldberg, Reds). doi:10.1007/1-84628-137-7_6
Examples
###############################################################################################
# Example 1. Basic Benchmark function in minimisation
###############################################################################################
# This basic Benchmark function has two objectives (M = 2) in minimisation, its Pareto optimal
# front is discontinuous with four disconnected curves.This function works with 2 decision
# variables (D = 2).
# Main reference for function: Deb (1999)
library(hydroMOPSO)
lower <- c(0, 0)
upper <- c(1, 1)
fnBasic <- function(param){
x1 <- param[1]
x2 <- param[2]
obj1 <- x1
obj2 <- (1 + 10*x2)*(1-(x1/(1+10*x2))^2 - x1/(1+10*x2)*sin(2*pi*4*x1))
out <- list(c(obj1, obj2)) # For consistency with further examples, this must be a list
names(out) <- "Objs" # The name "Objs" is a mandatory requirement
return(out)
}
set.seed(100) # Setting the seed (for reproducible results)
out <- hydroMOPSO(fn = fnBasic,
lower = lower,
upper = upper,
control=list(npart = 10, maxrep = 100, maxcross = 50,
MinMax = "min", maxit = 50, plot = TRUE)
)
###############################################################################################
# Example 2. Basic Benchmark function in maximisation
###############################################################################################
#
# This example is identical to Example 1, but the functions are in maximisation
#
# IMPORTANT:
# In the literature related to multi-objective optimisation, test functions are usually
# presented with minimisation objectives (such as the function used in Example 1). However,
# this does not necessarily always have to be formulated that way, especially when it comes to
# real-world applications.
#
# In this second example we just want to remind you that the disjunctive between maximising or
# minimising objectives is "a matter of signs".
#
# With this in account, as explained in the documentation, for hydroMOPSO operation there is
# one requirement which you MUST TAKE CARE OF:
#
# "The problems must be formulated in such a way that ALL objectives are either maximising or
# minimising. If your problem mixes both types of objectives, just add minus signs (-) in the
# results that require it..."
#
# Main reference for function: Kursawe (1991)
library(hydroMOPSO)
lower <- c(0, 0)
upper <- c(1, 1)
fnBasic <- function(param){
x1 <- param[1]
x2 <- param[2]
obj1 <- -( x1 )
obj2 <- -( (1 + 10*x2)*(1-(x1/(1+10*x2))^2 - x1/(1+10*x2)*sin(2*pi*4*x1)) )
# note tha minus sign was added in obj1 and obj2
out <- list(c(obj1, obj2)) # For consistency with further examples, this must be a list
names(out) <- "Objs" # The name "Objs" is a mandatory requirement
return(out)
}
set.seed(100) # Setting the seed (for reproducible results)
out <- hydroMOPSO(fn = fnBasic,
lower = lower,
upper = upper,
control=list(npart = 10, maxrep = 100, maxcross = 50,
MinMax = "max", maxit = 50, plot = TRUE) # note that now MinMax="max"
)
###############################################################################################
# Example 3. Using 'smoof' package: Kursawe function
###############################################################################################
#
# This Benchmark function has two objectives (M = 2), its Pareto optimal front is discontinuous
# and non-convex. For this example it will be implemented with 3 decision variables (D = 3)
#
# Main reference for function: Kursawe (1991)
library(hydroMOPSO)
library(smoof)
D <- 3
lower <- rep(-5,D)
upper <- rep(5,D)
Kursawe <- smoof::makeKursaweFunction(D) # using 'smoof' package
fnKursawe <- function(param){
objs <- Kursawe(x = param)
obj1 <- objs[1]
obj2 <- objs[2]
out <- list(c(obj1, obj2)) # For consistency with further examples, this must be a list
names(out) <- "Objs" # The name "Objs" is a mandatory requirement
return(out)
}
set.seed(100) # Setting the seed (for reproducible results)
out <- hydroMOPSO(fn = fnKursawe,
lower = lower,
upper = upper,
control=list(npart = 10, maxrep = 100, maxcross = 50,
MinMax = "min", maxit = 50, plot = TRUE)
)
###############################################################################################
# Example 4. Using 'smoof' package: DTLZ2 function with three objectives
###############################################################################################
#
# In this example, this Benchmark is formulated with two objectives (M = 3) and 12 decision
# variables (D = 12) its Pareto optimal front is concave.
#
# Main reference for function: Deb (2005)
library(hydroMOPSO)
library(smoof)
M <- 3
D <- 12
lower <- rep(0,D)
upper <- rep(1,D)
DTLZ2 <- smoof::makeDTLZ2Function(D, M) # using 'smoof' package
fnDTLZ2 <- function(param){
objs <- DTLZ2(x = param)
obj1 <- objs[1]
obj2 <- objs[2]
obj3 <- objs[3]
out <- list(c(obj1, obj2, obj3)) # For consistency with further examples, this must be a list
names(out) <- "Objs" # The name "Objs" is a mandatory requirement
return(out)
}
set.seed(100) # Setting the seed (for reproducible results)
out <- hydroMOPSO(fn = fnDTLZ2,
lower = lower,
upper = upper,
control=list(npart = 10, maxrep = 100, maxcross = 50,
MinMax = "min", maxit = 50, plot = TRUE)
)
###############################################################################################
# Example 5. Calibration of GR4J hydrological model
###############################################################################################
#
# For this example, a "real-world" problem has been formulated: the calibration of a
# hydrological model
#
# In detail...
# Hydrological model: GR4J (Perrin et al., 2004)
# Number of parameters: four (X1, X2, X3, X4; see Perrin et al. (2004))
# Study area: Trancura River Basin (RTL)
# Input variables: Precipitation (pcp) and Potetntial EvapoTranspiration (pet)
# Calibration output variable: Streamflow (qobs)
library(hydroMOPSO)
library(airGR)
library(hydroTSM)
library(hydroGOF)
# RTL basin ------------------------------------------------
basin.area <- 1415025887 # basin area in square meters
# Load time series -----------------------------------------
data(Trancura9414001plus) # Load RTL data set
# Dates ----------------------------------------------------
dates.raw <- Trancura9414001plus[,"Date"]
dates <- as.Date(dates.raw) # dates
# INPUTS time series ---------------------------------------
# Precipitation (input variable)
ts.pcp.raw <- Trancura9414001plus[,"P_mm"]
ts.pcp <- zoo(ts.pcp.raw, dates)
# Potential EvapoTranspiration (input variable)
ts.pet.raw <- Trancura9414001plus[,"PET_mm"]
ts.pet <- zoo(ts.pet.raw, dates)
# OUTPUTS time series --------------------------------------
# Observed streamflow (calibration output variable)
ts.qobs.raw <- Trancura9414001plus[,"Qobs_m3s"]
ts.qobs <- zoo(ts.qobs.raw, dates)
# Parameter ranges and noCal parameters --------------------
lower <- c("X1" = 0.01, "X2" = -100, "X3" = 0.01, "X4" = 0.5) # parameter range lower threshold
upper <- c("X1" = 1200, "X3" = 100, "X3" = 5000, "X4" = 5 ) # parameter range upper threshold
noCal.param <- (lower + upper)/2 # uncalibrated parameters
# Names and units of observed output variables -------------
char.obs.names <- "Streamflow"
char.obs.units <- "m3/s"
# Objectives names -----------------------------------------
char.objs.names <- c("KGE2012_Q", "KGEGarcia_Q")
# Calibration dates and subsetting -------------------------
WarmUpCal.dates <- dip("1979-01-01", "1979-12-31") # WarmUp for Calibration
Cal.dates <- dip("1980-01-01", "1999-12-31") # Calibration
FullCal.dates <- dip("1979-01-01", "1999-12-31") # WarmUp + Calibration
start.FullCal <- FullCal.dates[1]
end.FullCal <- FullCal.dates[length(FullCal.dates)]
# INPUTS time series ---------------------------------------
# Precipitation (input variable)
ts.pcp.FullCal <- window(ts.pcp, start = start.FullCal, end = end.FullCal) # subsetting pcp
# Potential EvapoTranspiration (input variable)
ts.pet.FullCal <- window(ts.pet, start = start.FullCal, end = end.FullCal) # subsetting pet
# OUTPUTS time series --------------------------------------
# Observed streamflow (calibration output variable)
ts.qobs.FullCal <- window(ts.qobs, start = start.FullCal, end = end.FullCal) # subsetting qobs
list.obs.Cal <- list(Q = ts.qobs.FullCal)
# Structuring Inputs and Options of GR4J model -------------
InputsModel.Cal <- CreateInputsModel(FUN_MOD= RunModel_GR4J,
DatesR= as.POSIXlt(FullCal.dates),
Precip= coredata(ts.pcp.FullCal),
PotEvap= coredata(ts.pet.FullCal))
RunOptions.Cal <- CreateRunOptions(FUN_MOD= RunModel_GR4J, InputsModel= InputsModel.Cal,
IndPeriod_Run = 1:length(FullCal.dates), warnings = FALSE)
# hydroMOPSO calibration -----------------------------------
set.seed(100) # Setting the seed (for reproducible results)
Cal.results <- hydroMOPSO(fn="hydromodInR",
lower=lower,
upper=upper,
control=list(MinMax="max", Xini.type = "lhs", npart=10,
maxit=50, # for better results set maxit=250 in this case
maxrep = 100, maxcross = 50,
maxeval = 15000, write2disk = FALSE, REPORT=1,
digits = 8, plot = TRUE, parallel = "none"),
model.FUN="GR4JExampleCal",
model.FUN.args = list(Obs=list.obs.Cal, # mandatory
Objs.names = char.objs.names, # mandatory
var.names = char.obs.names, # mandatory
var.units = char.obs.units, # mandatory
full.period = FullCal.dates, # mandatory
warmup.period = WarmUpCal.dates,
cal.period = Cal.dates,
# Model specific inputs
InputsModel = InputsModel.Cal, # model specific
RunOptions = RunOptions.Cal, # model specific
area = basin.area # model specific
)
)
Verification of a optimised model
Description
It takes the optimisation results of a model and reruns the simulations in a verification period. Only applicable when the results of the previous optimisation were done with fn=='hydromod' | fn=='hydromodInR'
Usage
hydroVerification(Results,
fn = NULL,
control = list(),
model.FUN = NULL,
model.FUN.args = list())
Arguments
Results |
( |
fn |
( When |
control |
( |
model.FUN |
( |
model.FUN.args |
( |
Value
(list
)
- ParticlesFull
(
data.frame
)
History of positions of each Pareto Front particles in all iterations. In thisdata.frame
, the first column indicates the simulation numberSim
, in ascending order from the first simulation (first iteration, phase 1) to the last simulation (last iteration, phase 2); then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- FilledPOF
(
data.frame
)
Filled Pareto front degraded in verification period. Keep in mind that strictly speaking this is not a Pareto Front since it is reached only by extending the solutions of the original front obtained by calibration to a verification period.
- ParticlesFilledPOF
(
data.frame
)
Perticles from filled Pareto Front. In thisdata.frame
, the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters). Note that in the objective columns the original calibration values have been replaced by those of the filled Pareto front degraded in verification period.
- ModelOut
(
list
)
Time series of the model output variables in verification period, for all solutions of the filled Pareto Front obtained in calibration period. This list has as many objects as output variables, and each one corresponds to an object of class zoo with as many columns as solutions of the filled Pareto Front.
- ParticleBestCS
(
data.frame
)
Best compromise solution, i.e., the solution with the minimum Euclidean distance from the maximum values of each objective, in calibration period. data.frame with only one row and several columns: the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters). Note that in the objective columns the original calibration values have been replaced by those obtained in the verification period.
- ModelOutBestCS
(
list
)
Time series of the model output variables in verification period, just for the best compromise solution obtained in calibration period. This list has as many objects as output variables, and each one corresponds to an object of class zoo with a single time serie.
- ParticleBestObjs
(
list
)
Solutions that minimise/maximise each of the objectives, obtained in calibration period. data.frame with only one row. In a first level, this list has as many objects as objectives involves in the optimisation, each one with a data.frame with only one row and several columns: the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters). Note that in the objective columns the original calibration values have been replaced by those obtained in the verification period.
- ModelOutBestObjs
(
list
)
Time series of the model output variables in verification period, for the maximisation/minimisation of each objective in calibration. In a first level, this list has as many objects as objectives involves in the optimisation and, in a second level, each one corresponds to a list with as many objects as output variables, each one corresponding to an object of class zoo with a single time serie.
- AnalysisPeriod
(
character
)
String indicating the analysis period, in this case"verification"
.
- DigitsDom
(
numeric
)
Number of decimal places used in dominance check. Fewer decimal places (say, 16, 8, or 4, for example) may be necessary to prevent the algorithm from resulting in solutions that are nearly the same.
- ObjsNames
(
data.frame
)
Name of each of the objectives (Obj1, Obj2, ...
).
- MaxMin
(
data.frame
)
Specification on whether the objectives are maximised or minimised, must be inc("max", "min")
.
- Obs
(
list
)
Observed values of each of the variables involved in the optimisation, but now of the verification period. Keep in mind that the same format indicated as mandatory input dataObs
within theFUN
function is maintained.
- Dimensions
(
data.frame
)
Number of objectives and number of output variables involved in the optimisation.
- NamesAndUnitsVars
(
data.frame
)
Name and unit of measure of the output variables involved in the optimisation (var1, var1_unit, var2, var2_unit, ...
).
- WarmUp
(
data.frame
)
Time series indicating the warm-up period used in the optimisation.
- DatesCal
(
data.frame
)
Time series indicating the calibration period used in the optimisation.
Note
1) The intended workflow is that first you must have the results of the optimisation done with the hydroMOPSO
function, which are then entered into this function (hydroVerification
)
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
hydroMOPSO
Definition and execution of the model to be optimised using an executable file that runs out of R (system console or external script)
Description
It runs a user-defined model to be optimised and returns the output variables of the model requested by the user according to the number of functions indicated in the list out.FUNs
.
This specific function was designed to run an executable file from the system console
Usage
hydromod(param.values,
param.files="ParamFiles.txt",
param.ranges="ParamRanges.txt",
model.drty=getwd(),
exe.fname,
exe.args = character(),
stdout=FALSE,
stderr="",
verbose= FALSE,
out.FUNs,
out.FUNs.args
)
Arguments
param.values |
( |
param.files |
character, file name (with full path) storing locations and names of the files that have to be modified for each parameter. By default |
param.ranges |
character, file name (with full path) storing the ranges (maximum and minum values) of the parameters to be used in the optimisation. By default |
model.drty |
( |
exe.fname |
( |
exe.args |
( |
stdout |
( |
stderr |
( |
verbose |
( |
out.FUNs |
( |
out.FUNs.args |
( |
Value
A list with as many output variables (usually time series in zoo class) as functions listed in out.FUNs
Author(s)
Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com, Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com
See Also
Plotting observed vs. simulated data and uncertainty bands
Description
The function plot_out
takes the optimization/calibration or verification
results of a hydrological model and generates the following plots:
(*): When do.png == TRUE
, graphics are written to disk.
(**): Multiple graphs are generated corresponding to the targets specified
in the optimization process.
-
ModelOut_BCS_from_Pareto_Optimal_Front_vs_Obs: A graphical comparison of time series for observed and simulated variables, using the simulation of the best compromise solution.
-
ModelOut_from_Pareto_Optimal_Front: An uncertainty band that encompasses the simulations given by all the solutions on the Pareto Optimal Front, displayed in a time series. The time series of the best compromise solution is also distinguished.
-
ModelOut_from_Pareto_Optimal_Front_vs_Obs: A graphical comparison of time series for observed and simulated variables, using an uncertainty band that encompasses the simulations given by all solutions on the Pareto Optimal Front.
Usage
plot_out(Results,
model.out = NULL,
analysis.period = NULL,
model.out.bcs = NULL,
bcs = NULL,
obs.var = NULL,
dimensions = NULL,
obj.names = NULL,
dates.cal = NULL,
dates.warmup = NULL,
var.names = NULL,
var.units = NULL,
xlim = NULL,
ylim = NULL,
digits = 4,
col.band = "skyblue",
col.bcs = "mediumblue",
col.obs = "black",
lwd = 0.75,
pch.bcs = 15,
pch.obs = 15,
main = "study case #1",
drty.out = "MOPSO.out",
cex.pt = 0.25,
cex.main = 1,
cex.lab = 1,
cex.axis = 1,
do.png = FALSE,
legend.obs = "Observation",
legend.bcs = "Best compromise solution",
legend.band = "Pareto front bands")
Arguments
Results |
( |
model.out |
( |
analysis.period |
( |
model.out.bcs |
( |
bcs |
( |
obs.var |
( |
dimensions |
( |
obj.names |
( |
dates.cal |
( |
dates.warmup |
( |
var.names |
( |
var.units |
( |
xlim |
( |
ylim |
( |
digits |
( |
col.band |
( |
col.bcs |
( |
col.obs |
( |
lwd |
( |
pch.bcs |
( |
pch.obs |
( |
main |
( |
drty.out |
( |
cex.pt |
( |
cex.main |
( |
cex.lab |
( |
cex.axis |
( |
do.png |
( |
legend.obs |
( |
legend.bcs |
( |
legend.band |
( |
Value
No return value; generates plots.
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
Plotting parameter with boxplots and dotty plots
Description
The function plot_param
generates plots to visualize parameter
sensitivity and distribution in the context of multi-objective optimization
using hydrological models. It helps in understanding how different parameters
affect the model's performance and the trade-offs involved.
(*): When do.png == TRUE
, graphics are written to disk.
Usage
plot_param(Results,
legend.param = NULL,
col = NULL,
col.param = NULL,
col.lines = NULL,
name.param = NULL,
lwd = 2,
main = "study case #1",
drty.out = "MOPSO.out",
cex.pt = 1,
cex.main = 1,
cex.lab = 1,
cex.axis = 1,
cex.leg = 1,
do.png = FALSE)
Arguments
Results |
( |
legend.param |
( |
col |
( |
col.param |
( |
col.lines |
( |
name.param |
( |
lwd |
( |
main |
( |
drty.out |
( |
cex.pt |
( |
cex.main |
( |
cex.lab |
( |
cex.axis |
( |
cex.leg |
( |
do.png |
( |
Value
No return value; generates plots as a side effect.
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
Plotting Pareto-optimal Fronts and Best Compromise Solutions
Description
The function plot_pof
generates plots of the Pareto-optimal front (POF)
and the best compromise solution (BCS) in multi-objective optimization for
hydrological models. It visualizes trade-offs between different objectives and
helps identify the most balanced solution, assisting in model calibration and
evaluation processes.
(*): When do.png == TRUE
, graphics are written to disk.
Usage
plot_pof(Results,
pof = NULL,
bcs = NULL,
analysis.period = NULL,
dimensions = NULL,
maxmin = NULL,
obj.thr = NULL,
obj.names = NULL,
main = "study case #1",
drty.out = "MOPSO.out",
pch.pof = 21,
pch.bcs = 21,
col.pof = "#f21b1b",
col.bcs = "#004fcf",
legend.pof = c("Pareto-optimal front solutions", "Best compromise solution"),
cex.pt = 1.25,
cex.main = 1,
cex.lab = 1,
cex.axis = 1,
do.png = FALSE)
Arguments
Results |
( |
pof |
( |
bcs |
( |
analysis.period |
( |
dimensions |
( |
maxmin |
( |
obj.thr |
( |
obj.names |
( |
main |
( |
drty.out |
( |
pch.pof |
( |
pch.bcs |
( |
col.pof |
( |
col.bcs |
( |
legend.pof |
( |
cex.pt |
( |
cex.main |
( |
cex.lab |
( |
cex.axis |
( |
do.png |
( |
Value
No return value; generates plots as a side effect.
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
Master Function for Plotting Hydrological Model Results
Description
The function plot_results
consolidates the plotting capabilities for
hydrological model outputs, Pareto-optimal front solutions, and parameter
sensitivity analyses. It calls three subordinate functions (plot_out
,
plot_pof
, plot_param
) to generate the required plots, offering
a comprehensive visualization tool for model evaluation and optimization results.
(*): When do.png == TRUE
, graphics are written to disk.
Usage
plot_results(Results,
model.out = NULL,
analysis.period = NULL,
model.out.bcs = NULL,
bcs = NULL,
obs.var = NULL,
dimensions = NULL,
obj.names = NULL,
dates.cal = NULL,
dates.warmup = NULL,
var.names = NULL,
var.units = NULL,
xlim = NULL,
ylim = NULL,
digits = 4,
col.band = "skyblue",
col.bcs = "mediumblue",
col.obs = "black",
lwd = 0.75,
pch.bcs = 15,
pch.obs = 15,
main = "study case #1",
drty.out = "MOPSO.out",
cex.pt.out = 0.25,
cex.pt.pof = 1.25,
cex.pt.param = 1,
cex.main = 1,
cex.lab = 1,
cex.axis = 1,
do.png = FALSE,
legend.obs = "Observation",
legend.bcs = "Best compromise solution",
legend.band = "Pareto front bands",
pof = NULL,
maxmin = NULL,
obj.thr = NULL,
pch.pof = 21,
col.pof = "#f21b1b",
legend.pof = c("Pareto-optimal front solutions",
"Best compromise solution"),
legend.param = NULL,
col = NULL,
col.param = NULL,
col.lines = NULL,
name.param = NULL,
cex.leg = 1)
Arguments
Results |
( |
model.out |
( |
analysis.period |
( |
model.out.bcs |
( |
bcs |
( |
obs.var |
( |
dimensions |
( |
obj.names |
( |
dates.cal |
( |
dates.warmup |
( |
var.names |
( |
var.units |
( |
xlim |
( |
ylim |
( |
digits |
( |
col.band |
( |
col.bcs |
( |
col.obs |
( |
lwd |
( |
pch.bcs |
( |
pch.obs |
( |
main |
( |
drty.out |
( |
cex.pt.out |
( |
cex.pt.pof |
( |
cex.pt.param |
( |
cex.main |
( |
cex.lab |
( |
cex.axis |
( |
do.png |
( |
legend.obs |
( |
legend.bcs |
( |
legend.band |
( |
pof |
( |
maxmin |
( |
obj.thr |
( |
pch.pof |
( |
col.pof |
( |
legend.pof |
( |
legend.param |
( |
col |
( |
col.param |
( |
col.lines |
( |
name.param |
( |
cex.leg |
( |
Value
No return value; generates plots as a side effect.
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
plot_out
, plot_pof
, plot_param
Reading the output files of a optimised model
Description
Read results saved on disk from an optimization with hydroMOPSO. This feature only applies when fn
is in c("hydromod", "hydromodInR")
Usage
read_results(fn = NULL,
control = list(),
model.FUN = NULL,
model.FUN.args = list()
)
Arguments
fn |
( When |
control |
( |
model.FUN |
( |
model.FUN.args |
( |
Details
The control
argument is a list that can supply any of the following components:
- drty.in
(
character
)
(OPTIONAL) Used only whenfn='hydromod'
Name of the directory storing the input files required for PSO, i.e. ‘ParamRanges.txt’ and ‘ParamFiles.txt’.- drty.out
(
character
)
Path to the directory storing the output files generated by hydroMOPSO.- digits
(
numeric
)
(OPTIONAL) Used only whenwrite2disk=TRUE
Number of significant digits used for writing the output files with scientific notation.- digits.dom
(
numeric
)
Number of decimal places used in dominance check. Fewer decimal places (say, 16, 8, or 4, for example) may be necessary to prevent the algorithm from resulting in solutions that are nearly the same.
By defaultdigits.dom=Inf
, which basically means numbers are not rounded- write2disk
(
logical
)
Indicates if the output files will be written to the disk.
By defaultwrite2disk=TRUE
- verbose
(
logical
)
Indicates if progress messages are to be printed.
By defaultverbose=TRUE
- REPORT
(
integer
)
(OPTIONAL) Used only whenverbose=TRUE
The frequency of report messages printed to the screen.
By defaultREPORT=10
- parallel
(
character
)
Indicates how to parallelise ‘hydroMOPSO’ (to be precise, only the evaluation of the objective functionfn
is parallelised). Valid values are:
-)none: no parallelisation is made (this is the default value)
-)parallel: parallel computations for network clusters or machines with multiple cores or CPUs. A ‘FORK’ cluster is created with themakeForkCluster
function. Whenfn.name='hydromod'
the evaluation of the objective functionfn
is done with theclusterApply
function of the parallel package. Whenfn.name != 'hydromod'
the evaluation of the objective functionfn
is done with theparRapply
function of the parallel package.
-)parallelWin: parallel computations for network clusters or machines with multiple cores or CPUs (this is the only parallel implementation that works on Windows machines). A ‘PSOCK’ cluster is created with themakeCluster
function. Whenfn.name='hydromod'
the evaluation of the objective functionfn
is done with theclusterApply
function of the parallel package. Whenfn.name != 'hydromod'
the evaluation of the objective functionfn
is done with theparRapply
function of the parallel package.- par.nnodes
(
numeric
)
(OPTIONAL) Used only whenparallel!='none'
Indicates the number of cores/CPUs to be used in the local multi-core machine, or the number of nodes to be used in the network cluster.
By defaultpar.nnodes
is set to the amount of cores detected by the functiondetectCores()
(parallel package)- par.pkgs
(
character
)
(OPTIONAL) Used only whenparallel='parallelWin'
List of package names (as characters) that need to be loaded on each node for allowing the objective functionfn
to be evaluated.
Value
(list
)
- MOPSOResults
(
list
)
Particle repository history of all iterations (both phases of NMPSO), detailing:
- ParetoFront (
data.frame
)
History of objectives values of each Pareto Front particles in all iterations (both phases). In thisdata.frame
, the first column indicates the iterationIter
; the second column the phasePhase
(1 or 2); and the following columns are as many as objectives treated, being identified with the assigned name.
- Particles_ParetoFront (data.frame
)
History of positions of each Pareto Front particles in all iterations (both phases). In thisdata.frame
, the first column indicates the iterationIter
; the second column the phasePhase
(1 or 2); then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- MaxMin (data.frame
)
Specification on whether the objectives are maximised or minimised.
- ObjsNames (data.frame
)
Name of each of the objectives (Obj1, Obj2, ...
).
- hydroDetails
(
list
)
(ONLY ADDED WHENfn=='hydromod' | fn=='hydromodInR'
)
Details about the modeling involved in optimisation:
- Dimensions (
data.frame
)
Number of objectives and number of output variables involved in the optimisation.
- NamesAndUnitsVars (data.frame
)
Name and unit of measure of the output variables involved in the optimisation (var1, var1_unit, var2, var2_unit, ...
).
- Obs (list
)
Observed values of each of the variables involved in the optimisation, keeping in mind that the same format indicated as mandatory input dataObs
within theFUN
function is maintained.
- WarmUp (data.frame
)
Time series indicating the warm-up period used in the optimisation.
- DatesCal (data.frame
)
Time series indicating the calibration period used in the optimisation.
- hydroResults
(
list
)
(ONLY ADDED WHENfn=='hydromod' | fn=='hydromodInR'
)
Post-processed results about the modeling involved in optimisation:
- ParticlesFull (
data.frame
)
History of positions of each Pareto Front particles in all iterations. In thisdata.frame
, the first column indicates the simulation numberSim
, in ascending order from the first simulation (first iteration, phase 1) to the last simulation (last iteration, phase 2); then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- FilledPOF (data.frame
)
Filled Pareto front, built from evaluating the dominance of the solutions of all the iterations performed in the optimisation. To prevent the filled Pareto Front from having too many solutions, the parameters and objective values are rounded according to inputDigitsDom
(number of decimal places). In thisdata.frame
, the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name.
- ParticlesFilledPOF (data.frame
)
Perticles from filled Pareto Front. In thisdata.frame
, the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- ModelOut (list
)
Time series of the model output variables, for all solutions of the filled Pareto Front. This list has as many objects as output variables, and each one corresponds to an object of class zoo with as many columns as solutions of the filled Pareto Front.
- ParticleBestCS (data.frame
)
Best compromise solution, i.e., the solution with the minimum Euclidean distance from the maximum values of each objective. data.frame with only one row and several columns: the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- ModelOutBestCS (list
)
Time series of the model output variables, just for the best compromise solution. This list has as many objects as output variables, and each one corresponds to an object of class zoo with a single time serie.
- ParticleBestObjs (list
)
Solutions that minimise/maximise each of the objectives. data.frame with only one row. In a first level, this list has as many objects as objectives involves in the optimisation, each one with a data.frame with only one row and several columns: the first column indicates the simulation numberSim
; then as many columns as objectives treated, being identified with the assigned name; and finally, as many columns as decision variables (parameters).
- ModelOutBestObjs (list
)
Time series of the model output variables, for the maximisation/minimisation of each objective. In a first level, this list has as many objects as objectives involves in the optimisation and, in a second level, each one corresponds to a list with as many objects as output variables, each one corresponding to an object of class zoo with a single time serie.
- AnalysisPeriod (character
)
String indicating the analysis period, in this case"calibration"
.
- DigitsDom (numeric
)
Number of decimal places used in dominance check. Fewer decimal places (say, 16, 8, or 4, for example) may be necessary to prevent the algorithm from resulting in solutions that are nearly the same.
- ObjsNames (data.frame
)
Name of each of the objectives (Obj1, Obj2, ...
).
- MaxMin (data.frame
)
Specification on whether the objectives are maximised or minimised, must be inc("max", "min")
.
- Obs (list
)
Observed values of each of the variables involved in the optimisation, keeping in mind that the same format indicated as mandatory input dataObs
within theFUN
function is maintained.
- Dimensions (data.frame
)
Number of objectives and number of output variables involved in the optimisation.
- NamesAndUnitsVars (data.frame
)
Name and unit of measure of the output variables involved in the optimisation (var1, var1_unit, var2, var2_unit, ...
).
- WarmUp (data.frame
)
Time series indicating the warm-up period used in the optimisation.
- DatesCal (data.frame
)
Time series indicating the calibration period used in the optimisation.
Note
1) The intended workflow is that first you must have the results of the optimisation done with the hydroMOPSO
function, having saved the results to disk (write2disk=TRUE
in hydroMOPSO
)
2) Based on the previous point, the user must ensure that the input arguments fn
, control
, model.FUN
and model.FUN.args
that are entered in the hydroMOPSO
and read_results
functions must be EXACTLY THE SAME
Author(s)
Rodrigo Marinao Rivas ra.marinao.rivas@gmail.com, Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
See Also
hydroMOPSO