Description Usage Arguments Details Examples
This is an implementation of the binary particle swarm optimization as described in Khanesar et al. (2007).
1 |
par |
Vector with length defining the dimensionality of the
optimization problem. Providing actual values of |
fn |
A function to be minimized (or maximized), with first argument the vector of parameters over which minimization is to take place. It should return a scalar result. |
... |
Further arguments to be passed to |
control |
A list of control parameters. See “Details”. |
By default this function performs minimization using a binary particle swarm
algorithm, but it will maximize if control$fnscale is negative.
The control argument is a list that can supply any of the following components:
Logical; if TRUE, tracing information on
the progress of the optimization is produced. Defaults to TRUE.
An overall scaling to be applied to the value of fn
during optimization. If negative, turns the problem into a maximization problem.
Optimization is performed on fn(par)/fnscale. Defaults to 1.
The maximum number of iterations. Defaults to 1000.
The frequency for reports if control$trace is
positive. Defaults to 10.
Logical; if TRUE statistics at every
reporting step are collected and returned. Defaults to FALSE.
The swarm size. Defaults to floor(10+2*sqrt(length(par))).
The inertia weight. Defaults to 1/(2*log(2)).
The local exploration constant. Defaults to 1+log(2).
The global exploration constant. Defaults to 1+log(2).
The maximal (euclidean) length of the velocity vector. Defaults to NA
which disables clamping of the velocity. Currently not implemented!
The maximum number of iterations without improvement.
Defaults to Inf.
A list with components:
\itempar
The best set of parameters found.
\itemvalue
The value of fn corresponding to par.
If trace.stats is TRUE additionally the component:
\itemstats
A list of statistics collected at every reporting step with the following components:
itThe iteration number
parThe currently best set of parameters.
valueThe corresponding value of fn.
fThe current values of fn of each particle.
xThe current particle positions as a matrix.
Algorithm is taken from: Khanesar, M.A et al. (2007)
Default parameters are taken from: Cortez, P. (2014) (http://www.springer.com/de/book/9783319082622)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | library('BPSO')
set.seed(123L)
n <- 30L
m <- 100L
x <- replicate(n, sample(x = c(0L, 1L), size = m, replace = TRUE), simplify = FALSE)
fn <- function (position) {
if(!any(position))
return(-Inf)
tmp <- do.call(what = rbind, args = x[position])
mean(apply(X = tmp, MARGIN = 2L, FUN = var))
}
fm <- bpsoptim(par = rep(FALSE, m), fn = fn,
control = list(maxit = 100L, REPORT = 5L),
debug = TRUE)
str(fm)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.