Permalink
Browse files

- computationally irrelevant: additional argument for *DDS to control…

… multi-particle runs. Cahngelog abandoned in favour of SVN comments

- error mesage for reversed parameter bounds
- minor typos
- added R-Studio project file
  • Loading branch information...
TillF committed Apr 14, 2015
1 parent 04f585d commit 66f5fc0e82399d534b6caa451d8360b7e54fa905
Showing with 350 additions and 315 deletions.
  1. +299 −296 ChangeLog
  2. +3 −2 DESCRIPTION
  3. +5 −1 R/init_particles.R
  4. +2 −2 R/optim_dds.R
  5. +1 −1 R/optim_pdds_robust.R
  6. +7 −7 R/update_tasklist_dds.R
  7. +1 −1 R/update_tasklist_pso.R
  8. +15 −5 man/optim_ppso.Rd
  9. +17 −0 ppso.Rproj
View
595 ChangeLog

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -1,11 +1,12 @@
Package: ppso
Type: Package
Title: Particle Swarm Optimization and Dynamically Dimensioned Search, optionally using parallel computing based on Rmpi
Version: 0.9-989
Date: 2014-09-23
Version: 0.9-990
Date: 2015-04-14
Author: Till Francke <francke@uni-potsdam.de>
Maintainer: Till Francke <francke@uni-potsdam.de>
Description: (Optionally parallelized) optimization using PSO (Particle Swarm Optimzation) or DDS (Dynamically Dimensioned Search) algorithms, which excell for multidimensional (multi-parameter) functions with many local extrema and a restricted number of function evaluations. The parallelized version builds on Rmpi and is intended for highly computationally intensive objective functions (>20 s evaluation time). Another focus of this package is the possibility to resume interrupted optimization runs from the intermediate project files. These features make this package useful for the automatic calibration of complex numerical models (e.g. hydrological models).\cr-- experimental version, use with care. Comments welcome --
Depends: R (>= 2.8.0)
Suggests: Rmpi (>= 0.5-7), rgl, lhs
License: Unlimited
NeedsCompilation: no
View
@@ -13,7 +13,7 @@ init_particles=function(lhc_init=FALSE)
if (is.data.frame(parameter_bounds)) parameter_bounds = as.matrix(parameter_bounds) #accept dataframes, too
if (length(parameter_bounds) != number_of_parameters*2) #ignore parameter_bounds, if in wrong format
{
warning("Corrupt parameter_bounds, ignored.")
warning("Corrupt parameter_bounds, resuming to defaults")
parameter_bounds = cbind(rep(-1, number_of_parameters),
rep(1, number_of_parameters))
assign(x="parameter_bounds", value=parameter_bounds, pos=parent.frame())
@@ -25,6 +25,10 @@ init_particles=function(lhc_init=FALSE)
assign(x="parameter_bounds", value=parameter_bounds, pos=parent.frame())
}
reversed = which((parameter_bounds[,1] > parameter_bounds[,2]))
if (any(reversed))
stop(paste("parameter bounds in row(s)",paste(reversed, collapse=", "), "are reversed."))
param_names=rownames(parameter_bounds) #try to retrieve parameter names
if (length(param_names)==0)
View
@@ -1,6 +1,6 @@
optim_dds <-
function (objective_function=sample_function, number_of_parameters=2, number_of_particles= 1, max_number_function_calls=500, r=0.2, abstol=-Inf, reltol=-Inf, max_wait_iterations=50,
parameter_bounds=cbind(rep(-1,number_of_parameters),rep(1,number_of_parameters)), initial_estimates=NULL, lhc_init=FALSE,
parameter_bounds=cbind(rep(-1,number_of_parameters),rep(1,number_of_parameters)), initial_estimates=NULL, lhc_init=FALSE, part_xchange=2,
#runtime & display parameters
do_plot=NULL, wait_for_keystroke=FALSE, logfile="dds.log",projectfile="dds.pro", save_interval=ceiling(number_of_particles/4),load_projectfile="try",break_file=NULL, plot_progress=FALSE, tryCall=FALSE, verbose=FALSE)
# do Dynamically Dimensioned Search (DDS) optimization (Tolson & Shoemaker 2007)
@@ -95,7 +95,7 @@ if (verbose_master) {print(paste(Sys.time(),"starting initialization runs..."))
globvars$node_id[pre_run_computations]), quote = FALSE, sep = "\t", row.names = FALSE, col.names = FALSE,append=TRUE)
if (any(globvars$fitness_X[pre_run_computations] %in% c(NA, NaN)))
stop("Objective function mustn't yield NA nor NaN. Modify it to return very large numbers instead.")
stop("Objective function mustn't yield NA or NaN. Modify it to return very large numbers instead.")
max_number_function_calls=max_number_function_calls-length(pre_run_computations) #reduce number of available calls due to pre-search
View
@@ -1,6 +1,6 @@
optim_pdds_robust <-
function (objective_function=sample_function, number_of_parameters=2, number_of_particles=1, max_number_function_calls=500, r=0.2, abstol=-Inf, reltol=-Inf, max_wait_iterations=50,
parameter_bounds=cbind(rep(-1,number_of_parameters),rep(1,number_of_parameters)), initial_estimates=NULL, lhc_init=FALSE,
parameter_bounds=cbind(rep(-1,number_of_parameters),rep(1,number_of_parameters)), initial_estimates=NULL, lhc_init=FALSE, part_xchange=2,
#runtime & display parameters
do_plot=NULL, wait_for_keystroke=FALSE, logfile="dds.log",projectfile="dds.pro", save_interval=ceiling(number_of_particles/4),load_projectfile="try",break_file=NULL, plot_progress=FALSE,
tryCall=FALSE, nslaves=-1, working_dir_list=NULL, execution_timeout=NULL, maxtries=10, verbose=FALSE)
View
@@ -37,7 +37,7 @@ update_tasklist_dds <- function(loop_counter=1)
}
if (any(globvars$fitness_X %in% c(NA, NaN)))
stop("Objective function mustn't yield NA nor NaN. Modify it to return very large numbers instead.")
stop("Objective function mustn't yield NA or NaN. Modify it to return very large numbers instead.")
# Update the local bests and their fitness
improved_particles=globvars$fitness_X < globvars$fitness_lbest #mark particles that improved their fitness
@@ -64,23 +64,23 @@ update_tasklist_dds <- function(loop_counter=1)
if (number_of_particles > 1)
{ #relocate "astray" particles
if (!exists('dds_ver')) dds_ver=2 #DDS-version (subtype for testing)
if (dds_ver==1) toberelocated = (globvars$futile_iter_count==max(globvars$futile_iter_count)) & (globvars$fitness_lbest==max(globvars$fitness_lbest)) & (globvars$fitness_lbest!=Inf) #1. find particles that are worst in both objective function AND improvement
if (dds_ver==2) toberelocated = (globvars$fitness_lbest > globvars$fitness_gbest) #2. relocate all but the best particle
if (dds_ver==3) toberelocated = which.max(globvars$futile_iter_count * (globvars$fitness_lbest!=min(globvars$fitness_lbest)))[1] #3. find particles is worst in improvement (but not the global best) and set to best improving particle
if (part_xchange==0) toberelocated = NULL #0. no relocation/updating
if (part_xchange==1) toberelocated = (globvars$futile_iter_count==max(globvars$futile_iter_count)) & (globvars$fitness_lbest==max(globvars$fitness_lbest)) & (globvars$fitness_lbest!=Inf) #1. find particle that is worst in both objective function AND futile iterations to improve
if (part_xchange==2) toberelocated = (globvars$fitness_lbest > globvars$fitness_gbest) #2. relocate all but the best particle
if (part_xchange==3) toberelocated = which.max(globvars$futile_iter_count * (globvars$fitness_lbest!=min(globvars$fitness_lbest)))[1] #3. find particles is worst in improvement (but not the global best) and set to best improving particle
if (any(toberelocated))
{
#cat(paste(sum(toberelocated),"particles globvars$relocated\n"))
if (do_plot!=FALSE) globvars$relocated=cbind(globvars$X_lbest[toberelocated,],globvars$fitness_lbest[toberelocated])
if ((dds_ver==1) || (dds_ver==2)) #version 1&2
if ((part_xchange==1) || (part_xchange==2)) #version 1&2
{
globvars$X_lbest [toberelocated,]= matrix(rep(globvars$X_gbest[],sum(toberelocated)),ncol=number_of_parameters, byrow = TRUE) #relocate particles to current best
globvars$fitness_lbest [toberelocated] = globvars$fitness_gbest #set to current best #could also be set to particle with lowest globvars$futile_iter_count
globvars$futile_iter_count[toberelocated] = 0 #zero iteration counter
}
if (dds_ver==3) #version 3
if (part_xchange==3) #version 3
{
most_recent_improved = which.min(globvars$futile_iter_count)[1] #get index to most recently improved particle
globvars$X_lbest [toberelocated,]= matrix(rep(globvars$X_lbest[most_recent_improved,],length(toberelocated)),ncol=number_of_parameters, byrow = TRUE) #relocate particles to current best
View
@@ -33,7 +33,7 @@ update_tasklist_pso=function() #update particle positions
if (is.na(globvars$ch)) globvars$ch=""
}
if (any(globvars$fitness_X %in% c(NA, NaN)))
stop("Objective function mustn't yield NA nro NaN. Modify it to return very large numbers instead.")
stop("Objective function mustn't yield NA or NaN. Modify it to return very large numbers instead.")
# Update the local bests and their fitness
View
@@ -24,10 +24,10 @@ optim_ppso_robust(objective_function = sample_function, number_of_parameters = 2
optim_dds (objective_function = sample_function, number_of_parameters = 2, number_of_particles = 1, max_number_function_calls= 500,
r=0.2, abstol = -Inf, reltol = -Inf, max_wait_iterations=50, parameter_bounds = cbind(rep(-1, number_of_parameters),
rep(1, number_of_parameters)), initial_estimates=NULL, lhc_init=FALSE, do_plot = NULL, wait_for_keystroke = FALSE, logfile= "dds.log", projectfile = "dds.pro", save_interval = ceiling(number_of_particles/4), load_projectfile = "try", break_file=NULL, plot_progress=FALSE, tryCall=FALSE, verbose=FALSE)
rep(1, number_of_parameters)), initial_estimates=NULL, part_xchange=2, lhc_init=FALSE, do_plot = NULL, wait_for_keystroke = FALSE, logfile= "dds.log", projectfile = "dds.pro", save_interval = ceiling(number_of_particles/4), load_projectfile = "try", break_file=NULL, plot_progress=FALSE, tryCall=FALSE, verbose=FALSE)
optim_pdds_robust(objective_function = sample_function, number_of_parameters = 2, number_of_particles = 1, max_number_function_calls= 500,
r=0.2, abstol = -Inf, reltol = -Inf, max_wait_iterations=50, parameter_bounds = cbind(rep(-1, number_of_parameters),
rep(1, number_of_parameters)), initial_estimates=NULL, lhc_init=FALSE, do_plot = NULL, wait_for_keystroke = FALSE, logfile= "dds.log", projectfile = "dds.pro", save_interval = ceiling(number_of_particles/4), load_projectfile = "try", break_file=NULL, plot_progress=FALSE, tryCall=FALSE, nslaves = -1, working_dir_list=NULL, execution_timeout=NULL, maxtries=10, verbose=FALSE)
rep(1, number_of_parameters)), initial_estimates=NULL, part_xchange=2, lhc_init=FALSE, do_plot = NULL, wait_for_keystroke = FALSE, logfile= "dds.log", projectfile = "dds.pro", save_interval = ceiling(number_of_particles/4), load_projectfile = "try", break_file=NULL, plot_progress=FALSE, tryCall=FALSE, nslaves = -1, working_dir_list=NULL, execution_timeout=NULL, maxtries=10, verbose=FALSE)
}
%- maybe also 'usage' for other objects documented here.
@@ -71,6 +71,7 @@ FALSE: Update particle velocities after each completed evaluation of function \c
(row-named) matrix containing columns of initial estimates (column-wise). If enough initial estimates were read from the project file, excess estimates in this parameter will be ignored. See details.
}
\item{Vmax}{
maximum velocity of particles in parameter space
}
@@ -108,7 +109,7 @@ If set to \code{TRUE}, \code{objective_function} is executed using \code{try}, w
}
for \code{optim_ppso*}:
for \code{optim_*pso*}:
\item{w}{
Inertia constant, i.e. "weight" of the particles.
@@ -120,14 +121,23 @@ Cognitive component. Weighting factor for the "personal" experience of each part
Social component. Weighting factor for the "swarm" experience of each particle.
}
for \code{optim_pdds*}:
for \code{optim_*dds*}:
\item{r}{
Neighbourhood size perturbation parameter . Default value: 0.2.
}
\item{part_xchange}{
Relevant for \code{number_of_particles} > 1: mode how DDS particles (i.e. parallel DDS-threads) communicate with each other between iterations:
\itemize{
\item{0:} {no communication/relocation between particles}
\item{1:} {relocate/update particle particle that is worst in both objective function AND futile iterations}
\item{2:} {relocate all but the best particle}
\item{3:} {relocate particle that is worst in futile iterations (but not the global best) and set to best improving particle}
}
for the parallel versions \code{optim_ppso*}, \code{optim_pdds*}:
\item{nslaves}{
\item{nslaves}{
number of rmpi slaves to spawn (default -1: as many as possible, requires package \code{Rmpi})
}
\item{working_dir_list}{
View
@@ -0,0 +1,17 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: ISO8859-1
RnwWeave: Sweave
LaTeX: pdfLaTeX
BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source

0 comments on commit 66f5fc0

Please sign in to comment.