bpsoptim: Binary Particle Swarm Optimization

Description Usage Arguments Details Examples

Description

This is an implementation of the binary particle swarm optimization as described in Khanesar et al. (2007).

Usage

1
bpsoptim(par, fn, ..., control = list(), debug = FALSE)

Arguments

par

Vector with length defining the dimensionality of the optimization problem. Providing actual values of par are not necessary (NA is just fine). If values are provided, the first particle will be initialized to the position provided by par.

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 fn.

control

A list of control parameters. See “Details”.

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:

trace:

Logical; if TRUE, tracing information on the progress of the optimization is produced. Defaults to TRUE.

fnscale:

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.

maxit:

The maximum number of iterations. Defaults to 1000.

REPORT:

The frequency for reports if control$trace is positive. Defaults to 10.

trace.stats:

Logical; if TRUE statistics at every reporting step are collected and returned. Defaults to FALSE.

s:

The swarm size. Defaults to floor(10+2*sqrt(length(par))).

w:

The inertia weight. Defaults to 1/(2*log(2)).

c.p:

The local exploration constant. Defaults to 1+log(2).

c.g:

The global exploration constant. Defaults to 1+log(2).

v.max:

The maximal (euclidean) length of the velocity vector. Defaults to NA which disables clamping of the velocity. Currently not implemented!

maxit.stagnate:

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:

it

The iteration number

par

The currently best set of parameters.

value

The corresponding value of fn.

f

The current values of fn of each particle.

x

The 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)

Examples

 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)

DominikMueller64/BPSO documentation built on May 6, 2019, 12:06 a.m.