Learn R Programming

hydroPSO (version 0.3-1-1)

ReadPlot_convergence: Reading/Plotting the values of different parameter sets

Description

This function reads a file containing different parameter sets and ther corresponfing goodness-of-fit values

Usage

read_convergence(file="ConvergenceMeasures.txt", MinMax=NULL, beh.thr=NA, 
     verbose=TRUE, plot=TRUE, col=c("black", "darkolivegreen"), lty=c(1,3), 
     lwd=c(2,2), main="Global Optimum & Normalized Swarm Radius vs Iteration Number", 
     xlab="Iteration Number", ylab=c("Global Optimum", expression(delta[norm])), 
     pch=c(15, 18), cex=1, cex.main=1.4, cex.axis=1.2, cex.lab=1.2, 
     legend.pos="topright", ..., do.png=FALSE, png.width=1500, png.height=900, 
     png.res=90,png.fname="ConvergenceMeasures.png")
           
plot_convergence(x, verbose=TRUE, col=c("black", "darkolivegreen"), lty=c(1,3),
     lwd=c(2,2), main="Global Optimum & Normalized Swarm Radius vs Iteration Number", 
     xlab="Iteration Number", ylab=c("Global Optimum", expression(delta[norm])), 
     pch=c(15, 18), cex=1, cex.main=1.4, cex.axis=1.2, cex.lab=1.2, 
     legend.pos="topright", ...,  do.png=FALSE, png.width=1500, png.height=900, 
     png.res=90, png.fname="ConvergenceMeasures.png")

Arguments

file
character, name (including path) of the file to be read
verbose
logical; if TRUE, progress messages are printed
x
data.frame with the convergence outputs obtained with read_convergence.
MinMax
OPTIONAL character, indicates if the optimum value in params corresponds to the minimum or maximum of the the objective function. Valid values are in: c('min', 'max')
beh.thr
numeric, used for selecting only the behavioural parameter sets, i.e., those with a goodness-of-fit value larger/lowervalue than beh.th, depending on the value of MinMax. It is only used for drawing a horizontal line used for se
plot
logical, indicates if a plot with the convergence measures has to be produced
col
OPTIONAL. Only used when plot=TRUE character, colour to be used for drawing the lines
lty
OPTIONAL. Only used when plot=TRUE numeric, line type to be used
lwd
OPTIONAL. Only used when plot=TRUE numeric, line width
xlab
OPTIONAL. Only used when plot=TRUE character, label for the 'x' axis
ylab
OPTIONAL. Only used when plot=TRUE character, label for the 'y' axis
main
OPTIONAL. Only used when plot=TRUE character, title for the plot
pch
OPTIONAL. Only used when plot=TRUE numeric, type of symbol for drawing the points of the dotty plots (e.g., 1: white circle)
cex
OPTIONAL. Only used when plot=TRUE numeric, values controlling the size of text and points with respect to the default
cex.main
OPTIONAL. Only used when plot=TRUE numeric, magnification to be used for main titles relative to the current setting of cex
cex.axis
OPTIONAL. Only used when plot=TRUE numeric, magnification to be used for axis annotation relative to the current setting of cex
cex.lab
OPTIONAL. Only used when plot=TRUE numeric, magnification to be used for x and y labels relative to the current setting of cex
legend.pos
OPTIONAL. Only used when plot=TRUE character, position of the legend. Valid values are in c("bottomright", "bottom", "bottomleft", "left", "topleft", "top", "topright", "right", "center"). See
...
OPTIONAL. Only used when plot=TRUE further arguments passed to the plot command or from other methods
do.png
logical, indicates if the plot with the convergence measures has to be saved into a PNG file instead of the screen device
png.width
OPTIONAL. Only used when do.png=TRUE numeric, width of the device. See png
png.height
OPTIONAL. Only used when do.png=TRUE numeric, height of the device. See png
png.res
OPTIONAL. Only used when 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
png.fname
OPTIONAL. Only used when do.png=TRUE character, name of the output PNG file. See png

Value

  • A list with the following elements:
  • Iteriteration number'
  • Gbestglobal optimum for each iteration
  • GbestRaterate of change of the global optimum (current iter/previous iter)
  • IterBestFitbest performance for the current iteration
  • normSwarmRadiusnormalised swarm radious
  • [gbest-mean(pbest)]/mean(pbest)gbest: global optimum, mean(pbest): mean values of the personal best of all the particles

See Also

read_results, plot_results

Examples

Run this code
# Setting the user home directory as working directory
setwd("~")

# Number of dimensions to be optimised
D <- 4

# Boundaries of the search space (Sphere function)
lower <- rep(-100, D)
upper <- rep(100, D)

# Setting the seed
set.seed(100)

# Runing PSO with the 'sphere' test function, writting the results to text files
hydroPSO(
        fn=sphere, lower=lower, upper=upper,
        control=list(MinMax="min", write2disk=TRUE, plot=TRUE)  
        )
  
# Reading the convergence measures got by running hydroPSO
setwd("PSO.out")
read_convergence()

Run the code above in your browser using DataLab