The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
This package collects the powerful variants of particle swarm optimization (PSO) and differential evolution (DE) algorithms for R users.
Currently it supports five types of PSO: - Particle Swarm Optimization (PSO, Eberhart and Kennedy, 1995) - Quantum-behaved particle Swarm Optimization (QPSO, Sun et al., 2004a,b) - Locally convergent rotationally invariant particle swarm optimization (LcRiPSO, Bonyadi and Michalewicz, 2014) - Competitive Swarm Optimizer (CSO, Cheng and Jin, 2015) - Double exponential particle swarm optimization (DExPSO, Stehlik et al., 2024+)
and six types of DE (Storn, R. and Price, K., 1997): - DE/rand/1: Mutation operation on the current position with one random direction. - DE/rand/2: Mutation operation on the current position with two random directions. - DE/best/1: Mutation operation on the best position with one random direction. - DE/best/2: Mutation operation on the best position with two random directions. - DE/rand_to-best/1: Mutation operation on the current position with direction to the best and one random direction. - DE/rand-to-best/2: Mutation operation on the current position with direction to the best and two random directions.
Please install the latest development version from github with
install.packages("devtools")
::install_github("PingYangChen/globpso") devtools
For setting the PSO type, please find the instruction through the command.
?getPSOInfo
library(globpso)
# Optimize the 3-dimensional quadratic objective function with location shift
<- function(x, loc) {
objf <- 0
val for (i in 1:length(x)) val <- val + (x[i] - loc)^2
return(val)
}
# The search domain is [-5, 5]^3
<- rep(5, 3)
upp_bound <- rep(-5, 3)
low_bound
# Define the location shift to be 1
<- 1
loc_shift
# Run PSO for this optimization problem
# Also input the enviorment variable, the location shift 'loc_shift'
<- globpso(objFunc = objf, lower = low_bound, upper = upp_bound,
res loc = loc_shift)
$par
res$val
res
# Set initial values to run PSO
<- c(2, 2, 2)
initSwarm # initSwarm <- rbind(c(2, 2, 2), c(1, 0.1, 1)) # for more than 2 initial points
<- globpso(objFunc = objf, lower = low_bound, upper = upp_bound,
res_i init = initSwarm, loc = loc_shift)
# One can also write C++ objective function to further accelerate the computation
library(Rcpp)
library(RcppArmadillo)
<- cppFunction('double objf_c(SEXP x, SEXP loc) {
objf_c double val = 0;
double loc_c = (double)Rcpp::as<double>(loc);
arma::rowvec x_c = (arma::rowvec)Rcpp::as<arma::rowvec>(x);
for (arma::uword i = 0; i < x_c.n_elem; i++) {
val += (x_c(i) - loc_c)*(x_c(i) - loc_c);
}
return val;
}', depends = "RcppArmadillo")
<- globpso(objFunc = objf_c, lower = low_bound, upper = upp_bound,
res_c loc = loc_shift)
$par
res_c$val
res_c
# Use getPSOInfo() to change the PSO options
<- getPSOInfo(nSwarm = 64, maxIter = 200, psoType = "quantum")
alg_setting <- globpso(objFunc = objf_c, lower = low_bound, upper = upp_bound, PSO_INFO = alg_setting, loc = loc_shift)
res_c_large $history res_c_large
For setting the DE type, please find the instruction through the command.
?getDEInfo
library(globpso)
# Optimize the 3-dimensional quadratic objective function with location shift
<- function(x, loc) {
objf <- 0
val for (i in 1:length(x)) val <- val + (x[i] - loc)^2
return(val)
}
# The search domain is [-5, 5]^3
<- rep(5, 3)
upp_bound <- rep(-5, 3)
low_bound
# Define the location shift to be 1
<- 1
loc_shift
# Use getDEInfo() to setup the DE options
<- getDEInfo(nPop = 64, maxIter = 200, deType = "best-2", sf = 0.5, cr = 0.1)
de_setting
# Run DE for this optimization problem
# Also input the enviorment variable, the location shift 'loc_shift'
<- diffevo(objFunc = objf, lower = low_bound, upper = upp_bound,
res DE_INFO = de_setting, verbose = FALSE, loc = loc_shift)
$par
res$val
res
# Simialr to PSO,
# One can also write C++ objective function to further accelerate the computation
If you encounter a bug, please file a reproducible example on github.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.