ReadPlot_results | R Documentation |
The function read_results
reads the following output files of hydroPSO:
1) ‘BestParameterSet.txt’: best parameter set and its corresponding goodness-of-fit found during the optimisation
2) ‘Particles.txt’: parameter values and their corresponding goodness-of-fit value for all particles and iterations
3) ‘Velocities.txt’: velocity values and their corresponding goodness-of-fit value for all particles and iterations
4) ‘Model_out.txt’: values of the objective function/model output for each particle and iteration
5) ‘ConvergenceMeasures.txt’: convergence measures summarizing performance of hydroPSO
6) ‘Particles_GofPerIter.txt’: goodness-of-fit only for all the particles during all the iterations
The function plot_results
takes the outputs of the read_results
function and then produces the following plots:
1) Dotty plots of parameter values
2) Histograms of parameter values
3) Boxplots of parameter values
4) Correlation matrix among parameter values (optional)
5) Empirical CDFs of parameter values
6) Parameter values vs Number of Model Evaluations
7) (pseudo) 3D dotty plots of (selected) parameter values
8) GoF for each particle against Number of Model Evaluations
9) Velocity values vs Number of Model Evaluations
10a) Scatterplot between Best Simulated values and Observations (OPTIONAL, only if MinMax
is provided)
10b) Empirical CDFs for model's output (only produced if obs
is NOT a zoo object)
10b) ggof (See ggof
) between Best Simulated values and Observations (OPTIONAL, only if obs
is a zoo object)
10d) Empirical CDFs for selected quantiles of model's output (OPTIONAL, only if obs
is a zoo object)
11) Convergence Measures (Gbest and normSwarmRadius) vs Iteration Number
read_results(drty.out="PSO.out", MinMax=NULL, beh.thr=NA,
modelout.cols=NULL, nsim=NULL, verbose=TRUE)
plot_results(drty.out="PSO.out", param.names, gof.name="GoF", MinMax=NULL,
beh.thr=NA, beh.col="red", beh.lty=1, beh.lwd=2, nrows="auto",
col="black", ylab=gof.name, main=NULL, pch=19, cex=0.5, cex.main=1.7,
cex.axis=1.3, cex.lab=1.5, breaks="Scott", freq=TRUE, do.pairs=FALSE,
weights=NULL, byrow=FALSE, leg.cex=1.2,
dp3D.names="auto", GOFcuts="auto",
colorRamp= colorRampPalette(c("darkred", "red", "orange", "yellow",
"green", "darkgreen", "cyan")), alpha=0.65, points.cex=0.7,
ptype="one",
nsim=NULL,
modelout.cols=NULL,
ftype="o", FUN=mean,
quantiles.desired= c(0.05,0.5,0.95),
quantiles.labels= c("Q5","Q50","Q95"),
legend.pos="topright",
do.png=FALSE, png.width=1500, png.height=900, png.res=90,
dotty.png.fname="Params_DottyPlots.png",
hist.png.fname ="Params_Histograms.png",
bxp.png.fname="Params_Boxplots.png",
ecdf.png.fname ="Params_ECDFs.png",
pruns.png.fname="Params_ValuesPerRun.png",
dp3d.png.fname ="Params_dp3d.png",
pairs.png.fname="Params_Pairs.png",
part.png.fname ="Particles_GofPerIter.png",
vruns.png.fname="Velocities_ValuePerRun.png",
modelout.best.png.fname="ModelOut_BestSim_vs_Obs.png",
modelout.quant.png.fname="ModelOut_Quantiles.png",
conv.png.fname ="ConvergenceMeasures.png", verbose=TRUE)
drty.out |
character, path to the directory storing the output files generated by |
param.names |
character, names for the parameters in |
verbose |
logical, if TRUE, progress messages are printed |
gof.name |
character, name of the goodness-of-fit variable in all plots |
MinMax |
OPTIONAL. character, indicates whether the optimum value in |
beh.thr |
OPTIONAL. numeric, threshold to filter out parameter sets and model outputs with a non-acceptable performance (non behavioural parameter sets) |
nsim |
OPTIONAL. number simulated equivalent values of the model / objective function to be compared against observations. |
modelout.cols |
numeric, column number in |
beh.col |
OPTIONAL. Only used when |
beh.lty |
OPTIONAL. Only used when |
beh.lwd |
OPTIONAL. Only used when |
nrows |
OPTIONAL. Only used when |
col |
OPTIONAL. Only used when |
ylab |
OPTIONAL. Only used when |
main |
OPTIONAL. Only used when |
pch |
OPTIONAL. Only used when |
cex |
OPTIONAL. Only used when |
cex.main |
OPTIONAL. Only used when |
cex.axis |
OPTIONAL. Only used when |
cex.lab |
OPTIONAL. Only used when |
breaks |
OPTIONAL. Only used when |
freq |
OPTIONAL. Only used when |
do.pairs |
OPTIONAL. Only used when |
weights |
OPTIONAL. Only used when |
byrow |
OPTIONAL. Only used when |
leg.cex |
OPTIONAL. Only used when |
dp3D.names |
character, name for all the parameters (usually only the most sensitive ones) that will be used for plotting pseudo-3D dotty plots |
GOFcuts |
numeric, specifies at which values of the objective function |
colorRamp |
R function defining the colour ramp to be used for colouring the pseudo-3D dotty plots of Parameter Values, OR character representing those colours. See |
alpha |
numeric between 0 and 1 representing the transparency level to apply to the colors of the pseudo-3D dotty plots. See |
points.cex |
size of the points to be plotted |
ptype |
character, represents the type of plot. Valid values are: in c("one", "many"), for plotting all the particles in the same figure or in one windows per particle, respectively |
ftype |
OPTIONAL. Only used when |
FUN |
OPTIONAL. Only used when |
quantiles.desired |
numeric vector, quantiles to be computed. Default values are c(.025, .5, .975) ( => 2.5%, 50%, 97.5% ). See |
quantiles.labels |
OPTIONAL. Only used when |
legend.pos |
See |
do.png |
logical, indicates if all the figures have to be saved into PNG files instead of the screen device |
png.width |
OPTIONAL. Only used when |
png.height |
OPTIONAL. Only used when |
png.res |
OPTIONAL. Only used when |
dotty.png.fname |
OPTIONAL. Only used when |
hist.png.fname |
OPTIONAL. Only used when |
bxp.png.fname |
OPTIONAL. Only used when |
ecdf.png.fname |
OPTIONAL. Only used when |
pruns.png.fname |
OPTIONAL. Only used when |
dp3d.png.fname |
OPTIONAL. Only used when |
pairs.png.fname |
OPTIONAL. Only used when |
part.png.fname |
OPTIONAL. Only used when |
vruns.png.fname |
OPTIONAL. Only used when |
modelout.best.png.fname |
OPTIONAL. Only used when |
modelout.quant.png.fname |
OPTIONAL. Only used when |
conv.png.fname |
OPTIONAL. Only used when |
The function read_results
returns a list with the following elements:
best.param |
numeric with the best parameter set |
best.gof |
numeric with the best fitness value of the objective function |
params |
data.frame with all the parameter sets tested during the optimisation |
gofs |
numeric with all the fitness values computed during the optimisation (each element in |
model.values |
numeric or matrix/data.frame with the values of the objective function / model for each particle and iteration. See |
model.best |
numeric with the best model / objective function value. In order to be computed, the user has to provide a valid value for |
model.obs |
numeric with the observed values used during the optimisation. See |
convergence.measures |
matrix/data.frame with the convergence measures. See |
part.GofPerIter |
matrix/data.frame with the goodness-of-fit values for all the particles during all the iterations. It has as many columns as parameters to be optimised and as many rows as the number of iterations effectively carried out |
Mauricio Zambrano-Bigiarini, mzb.devel@gmail.com
hydroPSO
, read_best
, read_particles
, read_velocities
, read_out
, read_convergence
, read_GofPerParticle
, plot_ParamsPerIter
# Setting the user home directory as working directory
setwd("~")
# Number of dimensions to be optimised
D <- 5
# Boundaries of the search space (Ackley test function)
lower <- rep(-32, D)
upper <- rep(32, D)
# Setting the seed
set.seed(100)
# Running PSO with the 'ackley' test function, writing the results to text files
hydroPSO(fn=ackley, lower=lower, upper=upper)
# Reading all the results and storing them in a variable
res <- read_results()
# Plotting all the results with a goodness-of-fit value lower than 5
plot_results(MinMax="min", beh.thr=5)
## Not run:
################################################################################
####################### SPSO-2007 example START ###############################
################################################################################
# Number of dimensions to be optimised
D <- 10
# boundaries for the test function
lower <- rep(-100, D) # sphere
#lower <- rep(-5.12, D) # rastrigin
#lower <- rep(-32, D) # ackley
fn <- sphere
#fn <-rastrigin
#fn <-ackley
#######################################
##### SPSO-2007 parameters ########
npart <- 10+floor(2*sqrt(D))
c1 <- 0.5+log(2)
c2 <- 0.5+log(2)
abstol <- 1e-20
reltol <- 1e-20
maxit <- 1000
use.IW <- TRUE
IW.w <- 1/(2*log(2))
REPORT <- 100
lambda <- 1
boundary.wall <- "absorbing2007"
#######################################
# Setting the user home directory as working directory
setwd("~")
# Running PSO and writing the results to text files
set.seed(100)
hydroPSO(fn= fn, method="spso2007", lower=lower, upper=-lower,
control=list(MinMax="min", maxit=maxit, npart=npart,
c1=c1, c2=c2,
use.IW=use.IW, IW.w=IW.w,
topology="random", lambda=lambda, K=3,
Xini.type="random", Vini.type="random2007",
best.update="sync",
boundary.wall=boundary.wall,
write2disk=TRUE, plot=FALSE, REPORT=REPORT,
abstol=abstol, reltol=reltol
)
)
# Plotting all the results
plot_results(MinMax="min")
################################################################################
####################### SPSO-2007 example END ###############################
################################################################################
################################################################################
############### recommended hydroPSO configuration - START #####################
################################################################################
# Running PSO and writing the results to text files
set.seed(100)
hydroPSO(fn= fn, method="spso2011", lower=lower, upper=-lower,
control=list(MinMax="min", maxit=maxit, npart=40,
c1=2.05, c2=2.05,
use.IW=FALSE, use.CF=TRUE,
topology="random", K=11,
use.TVlambda=TRUE, TVlambda.rng=c(1, 0.5),
Xini.type="lhs", Vini.type="lhs2011",
best.update="sync",
boundary.wall="absorbing2011",
write2disk=FALSE, plot=FALSE, REPORT=REPORT,
abstol=abstol, reltol=reltol
)
)
# compare the final optimum value and the number of function calls with those
# obtained in the SPSO-2007 example
################################################################################
################ recommended hydroPSO configuration - END ######################
################################################################################
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.