General implementation of particle swarm optimization usable as a direct
Vector with length defining the dimensionality of the
optimization problem. Providing actual values of
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.
A function to return the gradient if local search is BFGS.
If it is
Further arguments to be passed to
Lower bounds on the variables.
Upper bounds on the variables.
A list of control parameters. See “Details”.
By default this function performs minimization using a particle swarm
algorithm, but it will maximize if
control$fnscale is negative.
The default control arguments implies that the algorithm follows the Standard PSO 2007 implementation by Maurice Clerc, but the code also provides support for PSO 2011, clamping the maximal velocity, restarting when all particles converge to a single area and using BFGS as the local search direction.
control argument is a list that can supply any of the
Non-negative integer. If positive, tracing information on
the progress of the optimization is produced. Defaults to
An overall scaling to be applied to the value of
gr (if used) during optimization. If negative, turns the problem
into a maximization problem. Optimization is performed on
fn(par)/fnscale. Defaults to
The maximum number of iterations. Defaults to
The maximum number of function evaluations (not considering any
performed during numerical gradient computation). Defaults to
The absolute convergence tolerance. The method converges once the
best fitness obtained is less than or equal to
abstol. Defaults to
The tolerance for restarting. Once the maximal distance between the
best particle and all other particles is less than
the algorithm restarts. Defaults to
0 which disables the
check for restarting.
The frequency for reports if
positive. Defaults to
TRUE statistics at every
reporting step are collected and returned. Defaults to
The swarm size. Defaults to
type is “SPSO2011” in which case the default is
The exponent for calculating number of informants. Defaults to
The average percentage of informants for each particle. A value of
1 implies that all particles are fully informed. Defaults to
The exploitation constant. A vector of length
2. If the length is two, the actual constant used is gradially
w as the number of iterations or
function evaluations approach the limit provided.
The local exploration constant. Defaults to
The global exploration constant. Defaults to
The diameter of the search space. Defaults to the euclidean distance
The maximal (euclidean) length of the velocity vector. Defaults to
which disables clamping of the velocity. However, if specified the
actual clamping of the length is
TRUE the particles are processed in random
TRUE then the value of
rand.order does not matter. Defaults to
The maximum number of restarts. Defaults to
The maximum number of iterations without improvement.
TRUE the particles are processed in a vectorized
manner. This reduces the overhead associated with iterating over
each particle and may be more time efficient for cheap function
evaluations. Defaults to
If true, each normal PSO position update is followed by an
L-BFGS-B search with the provided position as initial guess. This
makes the implementation a hybrid approach. Defaults to
FALSE which disables BFGS for the local search. Note that
no attempt is done to control the maximal number of function
evaluations within the local search step (this can be done
hybrid.control) but the number of
function evaluations used by the local search method counts
towards the limit provided by
maxf AFTER the local search
returns. To support a broader class of hybrid approaches a
character vector can also be supplied with “off” being
equivalent to false, “on” equivalent to true, and
“improved” implying that the local search will only be
performed when the swarm finds an improvement.
List with any additional control parameters to pass on to
optim when using L-BFGS-B for the local search.
Character vector which describes which reference implementation of SPSO is followed. Can take the value of “SPSO2007” or “SPSO2011”. Defaults to “SPSO2007”.
A list, compatible with the output from
optim, with components:
The best set of parameters found.
The value of
A three-element vector containing the number of function evaluations, the number of iterations, and the number of restarts.
An integer code.
A descriptive message of the reason for termination.
trace is positive and
TRUE additionally the component:
A list of statistics collected at every reporting step with the following components:
Default parameters follow:
Clerc, M. et al. (2010)
type is “SPSO2011” in which case the differences
described in Clerc, M. (2011)
apply. Notice that the SPSO 2011 implementation does not include any
of the bells and whistles from the implementation by M. Clerc et
al. and effectively only differes from the SPSO 2007 implementation
in the default swarm size, how velocities are initiated and the
update of velocities/positions which in the SPSO 2011 implementation
are invariant to rotation.
The gradual change of
w and clamping the maximal velocity is
Parsopoulos, K.E. and Vrahatis M.N. (2002) Recent approaches to global optimization problems through Particle Swarm Optimization. Natural Computing 1: 235-306.
The restart (provided through
reltol) is similar to:
Evers G.I. and Ghalia M.B. Regrouping Particle Swarm Optimization: A New Global Optimization Algorithm with Improved Performance Consistency Across Benchmarks. http://www.georgeevers.org/RegPSO.pdf
The hybrid approach is similar to:
Qin J., Yin Y. and Ban X. (2010) A Hybrid of Particle Swarm Optimization and Local Search for Multimodal Functions. Lecture Notes in Computer Science, Volume 6145/2010, 589-596, DOI: 10.1007/978-3-642-13495-1_72
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
set.seed(1) ## Rastrigin function psoptim(rep(NA,2),function(x) 20+sum(x^2-10*cos(2*pi*x)), lower=-5,upper=5,control=list(abstol=1e-8)) set.seed(1) ## Rastrigin function - local refinement with L-BFGS-B on improvements psoptim(rep(NA,2),function(x) 20+sum(x^2-10*cos(2*pi*x)), lower=-5,upper=5,control=list(abstol=1e-8,hybrid="improved")) ## Griewank function psoptim(rep(NA,2),function(x) sum(x*x)/4000-prod(cos(x/sqrt(1:2)))+1, lower=-100,upper=100,control=list(abstol=1e-2)) set.seed(1) ## Rastrigin function with reporting o <- psoptim(rep(NA,2),function(x) 20+sum(x^2-10*cos(2*pi*x)), lower=-5,upper=5,control=list(abstol=1e-8,trace=1,REPORT=1, trace.stats=TRUE)) ## Not run: plot(o$stats$it,o$stats$error,log="y",xlab="It",ylab="Error") points(o$stats$it,sapply(o$stats$f,min),col="blue",pch=2) ## End(Not run)
$par  5.798684e-06 -1.490932e-08 $value  6.670927e-09 $counts function iteration restarts 1404 117 0 $convergence  0 $message  "Converged" $par  -5.309030e-14 3.867916e-15 $value  0 $counts function iteration restarts 720 58 0 $convergence  0 $message  "Converged" $par  3.082968 4.461188 $value  0.009153257 $counts function iteration restarts 324 27 0 $convergence  0 $message  "Converged" S=12, K=3, p=0.2297, w0=0.7213, w1=0.7213, c.p=1.193, c.g=1.193 v.max=NA, d=14.14, vectorize=FALSE, hybrid=off It 1: fitness=12.57 It 2: fitness=4.681 It 3: fitness=4.681 It 4: fitness=4.681 It 5: fitness=4.681 It 6: fitness=4.681 It 7: fitness=2.057 It 8: fitness=2.057 It 9: fitness=2.057 It 10: fitness=2.057 It 11: fitness=2.057 It 12: fitness=2.057 It 13: fitness=2.057 It 14: fitness=2.057 It 15: fitness=2.045 It 16: fitness=2.045 It 17: fitness=2.045 It 18: fitness=2.045 It 19: fitness=2.043 It 20: fitness=2.043 It 21: fitness=2.043 It 22: fitness=2.043 It 23: fitness=2.043 It 24: fitness=1.249 It 25: fitness=1.249 It 26: fitness=1.249 It 27: fitness=1.249 It 28: fitness=1.249 It 29: fitness=0.2882 It 30: fitness=0.2882 It 31: fitness=0.2882 It 32: fitness=0.2882 It 33: fitness=0.2882 It 34: fitness=0.2882 It 35: fitness=0.2882 It 36: fitness=0.2882 It 37: fitness=0.2882 It 38: fitness=0.2882 It 39: fitness=0.2882 It 40: fitness=0.2082 It 41: fitness=0.2082 It 42: fitness=0.2082 It 43: fitness=0.2082 It 44: fitness=0.2082 It 45: fitness=0.2082 It 46: fitness=0.2082 It 47: fitness=0.2082 It 48: fitness=0.2082 It 49: fitness=0.2082 It 50: fitness=0.2082 It 51: fitness=0.2082 It 52: fitness=0.2082 It 53: fitness=0.04564 It 54: fitness=0.04564 It 55: fitness=0.04564 It 56: fitness=0.03063 It 57: fitness=0.03063 It 58: fitness=0.03063 It 59: fitness=0.03063 It 60: fitness=0.01046 It 61: fitness=0.01046 It 62: fitness=0.01046 It 63: fitness=0.001615 It 64: fitness=0.001615 It 65: fitness=0.001615 It 66: fitness=0.001615 It 67: fitness=0.001615 It 68: fitness=0.001615 It 69: fitness=0.001615 It 70: fitness=0.001615 It 71: fitness=0.001615 It 72: fitness=0.0006849 It 73: fitness=0.0006849 It 74: fitness=0.0006849 It 75: fitness=0.0006593 It 76: fitness=0.0006593 It 77: fitness=0.0006593 It 78: fitness=0.0005541 It 79: fitness=0.0005541 It 80: fitness=0.0005541 It 81: fitness=0.0005207 It 82: fitness=0.0005207 It 83: fitness=0.0005207 It 84: fitness=0.0005158 It 85: fitness=0.0005158 It 86: fitness=4.629e-05 It 87: fitness=4.629e-05 It 88: fitness=4.629e-05 It 89: fitness=4.629e-05 It 90: fitness=4.629e-05 It 91: fitness=1.866e-05 It 92: fitness=1.866e-05 It 93: fitness=1.866e-05 It 94: fitness=1.866e-05 It 95: fitness=1.866e-05 It 96: fitness=1.866e-05 It 97: fitness=1.467e-05 It 98: fitness=1.284e-06 It 99: fitness=1.284e-06 It 100: fitness=1.284e-06 It 101: fitness=3.999e-07 It 102: fitness=3.999e-07 It 103: fitness=3.999e-07 It 104: fitness=2.943e-07 It 105: fitness=2.943e-07 It 106: fitness=2.943e-07 It 107: fitness=2.277e-07 It 108: fitness=2.277e-07 It 109: fitness=2.277e-07 It 110: fitness=2.277e-07 It 111: fitness=2.277e-07 It 112: fitness=2.277e-07 It 113: fitness=2.277e-07 It 114: fitness=7.275e-08 It 115: fitness=7.275e-08 It 116: fitness=7.275e-08 It 117: fitness=6.671e-09 Converged
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.