Description Usage Arguments Details Value Note Author(s) References See Also Examples
optim_pso
minimizes a given function objective_function
with regard to its parameters contained in the vector par
towards a minimum value of f using Particle Swarm Optimization.
optim_ppso_robust
is the parallelized versions (using multiple CPUs).
optim_dds
minimizes using a Dynamically Dimensioned Search with optim_pdds_robust
being the parallel version.
1 2 3 4 5 6 7 8 9 10 11 12 13 | optim_pso (objective_function = sample_function, number_of_parameters = 2, number_of_particles = 40, max_number_of_iterations = 5, max_number_function_calls=500,
w = 1, C1 = 2, C2 = 2, abstol = -Inf, reltol = -Inf, max_wait_iterations = 50, wait_complete_iteration = FALSE, parameter_bounds = cbind(rep(-1, number_of_parameters),
rep(1, number_of_parameters)), initial_estimates=NULL, Vmax = (parameter_bounds[, 2] - parameter_bounds[, 1])/3, lhc_init=FALSE, do_plot = NULL, wait_for_keystroke = FALSE, logfile = "ppso.log", projectfile = "ppso.pro", save_interval = ceiling(number_of_particles/4), load_projectfile = "try", break_file=NULL, plot_progress=FALSE, tryCall=FALSE, verbose=FALSE, ...)
optim_ppso_robust(objective_function = sample_function, number_of_parameters = 2, number_of_particles = 40, max_number_of_iterations = 5, max_number_function_calls=500,
w = 1, C1 = 2, C2 = 2, abstol = -Inf, reltol = -Inf, max_wait_iterations = 50, wait_complete_iteration = FALSE, parameter_bounds = cbind(rep(-1, number_of_parameters),
rep(1, number_of_parameters)), initial_estimates=NULL, Vmax = (parameter_bounds[, 2] - parameter_bounds[, 1])/3, lhc_init=FALSE, do_plot = NULL, wait_for_keystroke = FALSE, logfile = "ppso.log", projectfile = "ppso.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, ...)
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, 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, 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, ...)
|
objective_function |
function whose numerical return value is to be minimized. |
number_of_parameters |
Number of parameters to be optimized. |
number_of_particles |
Number of particles used in the Particle Swarm Optimization / number of parallel threads in DDS. |
max_number_of_iterations |
Abortion criterion: Maximum number of iterations (i.e. update of particle positions) that are used. |
max_number_function_calls |
Abortion criterion: Maximum total number of calls to the objective function, ignored when set to |
abstol |
Abortion criterion: minimum absolute improvement between iterations (default: -Inf) |
reltol |
Abortion criterion: minimum absolute relative improvement between iterations (default: -Inf) |
max_wait_iterations |
Number of iterations, within these an improvement of the above described ( |
wait_complete_iteration |
TRUE: Update particle velocities after function |
parameter_bounds |
(row-named) matrix containing lower (first column) and upper (second column) boundary for each parameter. See details. |
initial_estimates |
(row-named) matrix containing columns of initial estimates (column-wise). Pending computations from a resumed project file are used first, then all |
Vmax |
maximum velocity of particles in parameter space |
lhc_init |
set starting positions of particles using Latin Hypecube Sampling (TRUE, requires package |
logfile |
Name of logfile for optional logging of ALL model runs. NULL disables logging. If an prior optimization run is successfully resumed (see |
projectfile |
Name of project file for optional logging of state of optimization, which enables resuming aborted optimizations. An existing file is overwritten! NULL disables project file. |
save_interval |
minimum number of function evaluations to compute before the |
load_projectfile |
|
break_file |
Name of a file file that will cause the termination of the optimization when it is encountered. Useful for interrupting a running optimization gracefully. At start-up, any existing file of this name will be deleted. |
plot_progress |
If set to TRUE, corresponds to repeated call of |
tryCall |
If set to |
... |
additional arguments passed to |
for optim_*pso*
:
w |
Inertia constant, i.e. "weight" of the particles. |
C1 |
Cognitive component. Weighting factor for the "personal" experience of each particle. |
C2 |
Social component. Weighting factor for the "swarm" experience of each particle. |
for optim_*dds*
:
r |
Neighbourhood size perturbation parameter . Default value: 0.2. |
part_xchange |
Relevant for
|
for the parallel versions optim_ppso*
, optim_pdds*
:
nslaves |
number of rmpi slaves to spawn (default -1: as many as possible, requires package |
working_dir_list |
String matrix of working directories the slaves should change to. First column holds the hostname, the second column the directory.\ A hostname may be listed several times, if more than one slave is run on it. If a host is listed less times than it has slaves, the last entry will be recycled as necessary.\ The entry "default" denotes the directory all slaves of unlisted hosts will be change to. If missing, slaves on unlisted hosts will stay in the directory they are spawned in (don't ask me which this is).\ Beware: "~" apparently doesn't work, so rather use the full path. |
execution_timeout |
If set to a factor greater than 1, a slave whose execution time has exceeded ( |
maxtries |
Number of times a slave may exceed |
verbose |
generate screen output documenting the message passing |
"master"master generates output
"slaves" slaves generate output (into text files named "slave<nn>")
TRUE master and slaves generate output
for didactical purpose (only for two-parameter search and fast objective function, non-parallelized):
do_plot |
enable 3D-plot of response surface and search progress.
"base": use basic 3D-plotting functions.
"rgl": use moveable rgl-plotting (requires package |
wait_for_keystroke |
waiting for keystroke between iterations (e.g. for plotting). Option for changing into debug mode. |
If parameter_bounds
(dominant) or initial_estimates
has named rows, these names are used in vector passed to the the call to objective_function
.
recommended use:
optim_pso, optim_dds serial computation for fast objective functions and single core machines
optim_ppso_robust, optim_pdds_robust parallel computation: computationally demanding objective function and multi-core CPU or network slaves.
concerning reproducibility: setting the seed using set.seed()
should make results reproducable. However, in the parallel versions, the randomness introduced by the order of the results returned from the slaves cannot be controlled, so this may limit reproducibility.
The functions return a list with the elements
par |
parameters (ie location) of minimum found |
value |
value of objective function at minimum |
function_calls |
total number of function calls performed |
break_flag |
criterium that caused the termination of the algorithm ( |
- still in development, use with care, all comments welcome -
Parallelization is a great thing, especially when it works. On its dark side, you just parallelize errors and multiply debugging effort. Enabling verbose=TRUE
and tryCall=TRUE
may help to find the error.
Master or slave crashes can cause the entire session to stall, so restarting R may be necessary. Under Windows, orphaned mpi-sessions and slaves may have to be killed manually to prevent stalling the entire system: Use "Process Explorer" (free) and kill the smpd.exe-tree and mpiexec.exe.
Till Francke <francke_at_uni-potsdam.de>
Tolson, B. A., and C. A. Shoemaker (2007) Dynamically dimensioned search algorithm for computationally efficient watershed model calibration, Water Resour. Res., 43, W01413, doi:10.1029/2005WR004723. http://www.agu.org/journals/wr/wr0701/2005WR004723/
plot_optimization_progress
, sample_function
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | library(ppso)
#simple application (all file I/O disabled)
result = optim_pso(objective_function=rastrigin_function, projectfile=NULL, logfile=NULL)
print (result) #actual minimum -2 at (0,0)
result = optim_dds(objective_function=rastrigin_function, projectfile=NULL, logfile=NULL)
print (result)
## Not run:
#simple application with visualisation
result = optim_pso(objective_function=rastrigin_function, projectfile=NULL, logfile=NULL, do_plot="rgl")
print (result)
result = optim_dds(objective_function=rastrigin_function, projectfile=NULL, logfile=NULL, do_plot="base")
print (result)
## End(Not run)
#writing and resuming from project file
projectfile =tempfile()
result = optim_pso(objective_function=rastrigin_function, projectfile=projectfile, logfile=NULL, load_projectfile="no") #start optimization, generate project file
print (result)
result = optim_pso(objective_function=rastrigin_function, projectfile=projectfile, logfile=NULL, load_projectfile="yes") #resume optimization from previous project file
print (result)
unlink(projectfile) #delete project file
## Not run:
#visualisation of progress
projectfile =tempfile()
logfile =tempfile()
result = optim_pso(objective_function=rastrigin_function, projectfile=projectfile, logfile=logfile, load_projectfile="no", plot_progress=TRUE) #start optimization, generate project file and log file
unlink(c(projectfile,logfile)) #delete log file and project file
#parallel application
result = optim_ppso_robust(objective_function=rastrigin_function, nslaves=2, max_number_function_calls=200, projectfile=NULL, logfile=NULL)
print (result)
result = optim_pdds_robust(objective_function=rastrigin_function, nslaves=2, max_number_function_calls=200, projectfile=NULL, logfile=NULL)
print (result)
working_dir_list=rbind( #specify working directories for four slaves
c(host="default", wd="/tmp/defaultdir"),
c(host="host1", wd="/home/me/firstthread"),
c(host="host1", wd="/home/me/secondthread"),
c(host="host2", wd="/home/me2/onlyonethread")
)
result = optim_pdds_robust(objective_function=rastrigin_function, nslaves=4, working_dir_list=working_dir_list)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.