pso {gena} | R Documentation |
Particle Swarm Optimization
Description
This function allows to use particle swarm algorithm for numeric global optimization of real-valued functions.
Usage
pso(
fn,
gr = NULL,
lower,
upper,
pop.n = 40,
pop.initial = NULL,
pop.method = "uniform",
nh.method = "random",
nh.par = 3,
nh.adaptive = TRUE,
velocity.method = "hypersphere",
velocity.par = list(w = 1/(2 * log(2)), c1 = 0.5 + log(2), c2 = 0.5 + log(2)),
hybrid.method = "rank",
hybrid.par = 2,
hybrid.prob = 0,
hybrid.opt.par = NULL,
hybrid.n = 1,
constr.method = NULL,
constr.par = NULL,
random.order = TRUE,
maxiter = 100,
is.max = TRUE,
info = TRUE,
...
)
Arguments
fn |
function to be maximized i.e. fitness function. |
gr |
gradient of the |
lower |
lower bound of the search space. |
upper |
upper bound of the search space. |
pop.n |
integer representing the size of the population. |
pop.initial |
numeric matrix which rows are particles to be included into the initial population. Numeric vector will be coerced to single row matrix. |
pop.method |
the algorithm to be applied for a creation of the initial population. See 'Details' for additional information. |
nh.method |
string representing the method (topology) to be used for the creation of neighbourhoods. See 'Details' for additional information. |
nh.par |
parameters of the topology algorithm. |
nh.adaptive |
logical; if |
velocity.method |
string representing the method to be used for the update of velocities. |
velocity.par |
parameters of the velocity formula. |
hybrid.method |
hybrids selection algorithm i.e. mechanism determining which particles should be subject to local optimization. See 'Details' for additional information. |
hybrid.par |
parameters of the hybridization algorithm. |
hybrid.prob |
probability of generating the hybrids each iteration. |
hybrid.opt.par |
parameters of the local optimization function
to be used for hybridization algorithm (including |
hybrid.n |
number of hybrids that appear if hybridization should take place during the iteration. |
constr.method |
the algorithm to be applied for imposing constraints on the particles. See 'Details' for additional information. |
constr.par |
parameters of the constraint algorithm. |
random.order |
logical; if |
maxiter |
maximum number of iterations of the algorithm. |
is.max |
logical; if |
info |
logical; if |
... |
additional parameters to be passed to
|
Details
Default arguments have been set in accordance with SPSO 2011 algorithm proposed by M. Clerc (2012).
To find information on particular methods available via
pop.method
, nh.method
, velocity.method
,
hybrid.method
and constr.method
arguments please see 'Details' section of
gena.population
, pso.nh
,
pso.velocity
, gena.hybrid
and gena.constr
correspondingly.
It is possible to provide manually implemented functions for population
initialization, neighbourhoods creation, velocity updated, hybridization
and constraints in a similar way as for gena
.
By default function does not impose any constraints upon the parameters.
If constr.method = "bounds"
then lower
and upper
constraints will be imposed. Lower bounds should be strictly smaller
then upper bounds.
Currently the only available termination condition is maxiter
. We
are going to provide some additional termination conditions during
future updates.
Infinite values in lower
and upper
are substituted with
-(.Machine$double.xmax * 0.9)
and .Machine$double.xmax * 0.9
correspondingly.
By default if gr
is provided then BFGS algorithm will be used inside
optim
during hybridization.
Otherwise Nelder-Mead
will be used.
Manual values for optim
arguments may be provided
(as a list) through hybrid.opt.par
argument.
For more information on particle swarm optimization please see M. Clerc (2012).
Value
This function returns an object of class pso
that is a list
containing the following elements:
-
par
- particle (solution) with the highest fitness (objective function) value. -
value
- value offn
atpar
. -
population
- matrix of particles (solutions) of the last iteration of the algorithm. -
counts
- a two-element integer vector giving the number of calls tofn
andgr
respectively. -
is.max
- identical tois.max
input argument. -
fitness.history
- vector which i-th element is fitness of the best particle in i-th iteration. -
iter
- last iteration number.
References
M. Clerc (2012). Standard Particle Swarm Optimisation. HAL archieve.
Examples
## Consider Ackley function
fn <- function(par, a = 20, b = 0.2)
{
val <- a * exp(-b * sqrt(0.5 * (par[1] ^ 2 + par[2] ^ 2))) +
exp(0.5 * (cos(2 * pi * par[1]) + cos(2 * pi * par[2]))) -
exp(1) - a
return(val)
}
# Maximize this function using particle swarm algorithm
set.seed(123)
lower <- c(-5, -100)
upper <- c(100, 5)
opt <- pso(fn = fn,
lower = lower, upper = upper,
a = 20, b = 0.2)
print(opt$par)
## Consider Bukin function number 6
fn <- function(x, a = 20, b = 0.2)
{
val <- 100 * sqrt(abs(x[2] - 0.01 * x[1] ^ 2)) + 0.01 * abs(x[1] + 10)
return(val)
}
# Minimize this function using initially provided
# position for one of the particles
set.seed(777)
lower <- c(-15, -3)
upper <- c(-5, 3)
opt <- pso(fn = fn,
pop.init = c(8, 2),
lower = lower, upper = upper,
is.max = FALSE)
print(opt$par)