Description Usage Arguments Details Value Note Author(s) References Examples

In computer science, the PSO is a computational method for optimization of parametric and multiparametric functions. The PSO algorithm is a meta-heuristic method, which has been providing good solutions for problems of global optimization functions with box-constrained. As in most heuristic methods that are inspired by biological phenomena, the PSO method is inspired by the behavior of flying birds. The philosophical idea of the PSO algorithm is based on the collective behavior of birds (particle) in search of food (point of global optimal).

The `pso`

function is an efficient function for global minimization, wherein it is not necessary to provide Initial kicks. This is the function for general purpose optimization.

1 |

`func` |
Objective function, i.e, function to be minimized; |

`S` |
Particle number considered. By default, S = 350; |

`lim_inf` |
Vector with the lower limit of the search for the parameters of the objective function that will be minimized; |

`lim_sup` |
Vector with the upper limits of search for the parameters of the objective function that will be minimized; |

`e` |
Stop value of the algorithm, i.e., if the variance of the last 20 minimum values is less than or equal to |

`data` |
Vector of data provided in the event of function to be minimized (passed as an argument for |

`N` |
Minimum number of iterations. By default, |

`prop` |
Proportion of last minimum value that is calculated variance used as a stopping criterion. That is, if the number of iterations is greater or equal to the minimum number of iterations |

.

The PSO optimizes a problem by having a population of candidate solutions and moving these particles around in the search-space according to simple mathematical formulae over the particle’s position and velocity. The movement of the particles in the search space is randomized. Each iteration of the PSO algorithm, there is a leader particle, which is the particle that minimizes the objective function in the corresponding iteration. The remaining particles arranged in the search region will follow the leader particle randomly and sweep the area around this leading particle. In this local search process, another particle may become the new leader particle and the other particles will follow the new leader randomly. Each particle arranged in the search region has a velocity vector and position vector and its movement in the search region is given by changes in these vectors.

As a stopping criterion is considered the variance of the last 20 minimum values estimated by the algorithm. If this variance is less or equal the `e`

the algorithm will stop providing the global minimum value. This is a conditional criterion, which will only be evaluated if the number of iterations is greater than or equal to the minimum number of iterations set to `N`

.

The amount of minimum values considered in the calculation of the variance is given by the proportion of minimum values established by the argument `prop`

which by default is `prop = 0.2`

. That is, if the last 20% (`prop = 0.2`

) of the minimum values has less variance than or equal to `e`

, the algorithm will stop global search, indicating convergence according to the established criteria. This indicates that there was no significant improvements in this proportion of last iterations.

`par_pso` |
Global minimum point; |

`f_pso` |
Global minimum value. |

In other versions of the package, the paper with more details that complement the documentation of this function will be provided in the above references and this note will be undone.

Pedro Rafael Diniz Marinho [email protected]

Beni G, Wang J (1993). Swarm intelligence in cellular robotic systems. pp. 703-712.

Eberhart RC, Kennedy J (1995). A new optimizer using particle swarm theory. In Proceedings of the sixth international symposium on micro machine and human science, volume 1, pp. 39-43. New York, NY.

Kennedy J, Kennedy JF, Eberhart RC, Shi Y (2001). Swarm intelligence. Morgan Kaufmann.

Shi Y, Eberhart R (1998). A modified particle swarm optimizer. In Evolutionary Computation Proceedings, 1998. IEEE World Congress on Computational Intelligence., The 1998 IEEE International Conference on, pp. 69-73. IEEE.

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 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | ```
# The objective functions below are rather difficult to be optimized.
# However, the function pso has great results.
# Example 1 (Easom function):
easom_function <- function(par,x){
x1 = par[1]
x2 = par[2]
-cos(x1)*cos(x2)*exp(-((x1-pi)^2 + (x2-pi)^2))
}
set.seed(0)
result_1 = pso(func = easom_function, S = 500, lim_inf = c(-10,-10), lim_sup = c(10,10),
e = 0.00001)
result_1$par
# Example 2 (Holder table function):
holder <- function(par,x){
x1 = par[1]
x2 = par[2]
-abs(sin(x1)*cos(x2) * exp(abs(1 - sqrt(x1^2+x2^2)/pi)))
}
set.seed(0)
result_2 = pso(func = holder, S = 700, lim_inf = c(-10,-10), lim_sup = c(10,10),
e = 0.00001, N=500)
result_2$par
# Example 3:
f_pso <- function(par,x){
theta = par[1]
-(6 + theta^2 * sin(14*theta))
}
set.seed(0)
result_3 <- pso(func = f_pso, S = 500, lim_inf = c(-2.5), lim_sup = c(2.5), e = 0.0001)
result_3$par
# TO RUN THE CODE BELOW, UNCOMMENT THE CODES.
# Example 4 (maximizing a function of the log-likelihood function):
# pdf_exp <- function(par,x){
# lambda = par[1]
# lambda*exp(-lambda*x)
#}
# -log-likelihood function of the exponential distribution.
#likelihood <- function(par,x){
# lambda = par[1]
# -sum(log(pdf_exp(par,x)))
#}
#set.seed(0)
#random_data1 = rexp(500,1)
#result_1 = pso(func = likelihood, S = 250, lim_inf = c(0), lim_sup = c(100), e = 0.0001,
# data = random_data1, N = 50, prop = 0.2)
#x = seq(0,ceiling(max(random_data1)), length.out = 500)
#hist(random_data1, probability = TRUE)
#lines(x, pdf_exp(par = result_1$par, x), col = "blue")
# Example 5 (maximizing a function of the log-likelihood function):
# Probability density function (Weibull)
#pdf_weibull <- function(par,x){
# a = par[1]
# b = par[2]
# dweibull(x,shape=a,scale=b)
#}
# -log-likelihood function of the Weibull distribution.
#likelihood <- function(par,x){
# -sum(log(pdf_weibull(par,x)))
#}
#set.seed(0)
#random_data2 = rweibull(250,2,2)
#result_2 = pso(func = likelihood, S = 250, lim_inf = c(0,0), lim_sup = c(10,10), e = 0.0001,
# data = random_data2, N = 50, prop = 0.2)
#x = seq(0,ceiling(max(random_data2)), length.out = 500)
#hist(random_data2, probability = TRUE, ylim = c(0,0.5))
#lines(x, pdf_weibull(par = result_2$par, x), col = "blue")
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.