read_results
reads the following output files of hydroPSO:
1) hydroPSO
6) 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 Numberread_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)
hydroPSO
params
that have to be plotted (param.names
can be a subset of params
).
Names for each parameter are taken from the first row of the x
corresponds to the minimum or maximum of the objective function. It is only used to identify the optimum on the plots
Valid values are in: c('min', 'max')
NA
instead of the simulated values for some parameter set(s) (e.g.,file
that store the outputs that have to be read/plotted, without counting the first three that correspond to iteration, particle and GoF. If modelout.cols=NULL
, all the columns in will be read
plot=TRUE
character, colour for drawing a horizontal line for separating behavioural from non behavioural parameter setsplot=TRUE
numeric, line type for drawing a horizontal line for separating behavioural from non behavioural parameter setsplot=TRUE
numeric, width for drawing a horizontal line for separating behavioural from non behavioural parameter setsplot=TRUE
numeric, number of rows to be used in the plotting window
If nrows
is set to auto, the number of rows is automatically computed depending on the number of columns of x
plot=TRUE
character, colour to be used for drawing the points of the dotty plotsplot=TRUE
character, label for the 'y' axisplot=TRUE
character, title for the plotplot=TRUE
numeric, type of symbol to be used for drawing the points of the dotty plots. (e.g., 1: white circle)plot=TRUE
numeric, values controlling the size of text and points with respect to the defaultplot=TRUE
numeric, magnification for main titles relative to the current setting of cex
plot=TRUE
numeric, magnification for axis annotation relative to the current setting of cex
plot=TRUE
numeric, magnification for x and y labels relative to the current setting of cex
plot=TRUE
breaks for plotting the histograms of the parameter sets. See hist
plot=TRUE
logical, if TRUE, the histogram graphic is a representation of frequencies, the counts component of the result; if FALSE, probability densities, component density, are plotted (so that the histogram has a tplot=TRUE
logical, indicates whether a correlation matrix among parameters has to be plotted. If the number of parameter sets tried during the optimisation is large, it may require some time.plot=TRUE
numeric vector, values of the weights to be used for computing the empirical CDFs. See params2ecdf
plot=TRUE
logical, indicates whether the computations have to be made for each column or for each row of x
. See params2ecdf
plot=TRUE
character expansion factor *relative* to current 'par("cex")'. Used for text, and provides the default for 'pt.cex' and 'title.cex'. Default value = 1.2dp3D.names='auto'
half the number of parameters in file
are chosen randomly for plotting. See gof.name
the colours of the plot have to change. See plot_NparOF
plot_NparOF
plot_NparOF
plot_GofPerParticle
plot_out
plot=TRUE
character vector, names to quantiles.desired
. Default value is c("Q5", "Q50", "Q95"). See plot_out
plot_convergence
do.png=TRUE
numeric, width of the PNG device. See png
do.png=TRUE
numeric, height of the PNG device. See png
do.png=TRUE
numeric, nominal resolution in ppi which will be recorded in the PNG file, if a positive integer of the device. See png
do.png=TRUE
character, filename used to store the PNG file with the dotty plots of the parameter values.do.png=TRUE
character, filename used to store the PNG file with the histograms of the parameter values.do.png=TRUE
character, filename used to store the PNG file with the boxplots of the parameter valuesdo.png=TRUE
character, filename used to store the PNG file with the empirical CDFs of the parameter values.do.png=TRUE
character, filename used to store the PNG file with the parameter values vs the number of model evaluationsdo.png=TRUE
character, filename used to store the PNG file with the pseudo-3D plots of all the parameters defined in dp3D.names
do.png=TRUE
character, filename used to store the PNG file with the correlation matrix among the parameters and goodness-of-fits measures in params
and gofs
. See
do.png=TRUE
character, filename used to store the PNG file with the goodness-of-fit for all the particles along the iterationsdo.png=TRUE
character, filename used to store the PNG file with the velocity values vs the number of model evaluationsdo.png=TRUE
character, filename used to store the PNG file with the observed values against its best simulated counterpart. See plot_out
do.png=TRUE
character, filename used to store the PNG file with some quantiles of simulated values against its observed counterparts. See plot_out
do.png=TRUE
character, filename used to store the PNG file with the convergence measures. See plot_convergence
read_results
returns a list with the following elements:gofs
corresponds to one row of params
)read_out
MinMax
. See read_out
obs
read_convergence
functionhydroPSO
, 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)
################################################################################
####################### 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 ######################
################################################################################
Run the code above in your browser using DataLab