BAS with momentum introduces 'velocity' to the detecting rules of basic BAS. It is more like the individual version of BSO The paper of this algorithm is not available now. If you have any question, please contact Xiaoxiao Li (xiaoxiaoli1993@sina.com)

BASoptim2(fn, init = NULL, lower = c(-6, 0), upper = c(-1, 2),
  constr = NULL, c = 2, l0 = 0, l1 = 0, eta_l = 0.95,
  step0 = 5e-05, step = 0.8, eta_step = 0.95, n = 200,
  seed = NULL, trace = T, steptol = step0/2, pen = 1e+05,
  w0 = 0.7, w1 = 0.2, c0 = 0.6)

Arguments

fn

objective function; function need to be optimized

init

default = NULL, it will generate randomly; Of course, you can specify it.

lower

lower of parameters to be estimated; Default = c(-6,0) because of the test on Michalewicz function of which thelower is c(-6,0); By the way, you should set one of init or lower parameter at least to make the code know the dimensionality of your problem.

upper

upper of parameters; Default = c(-1,2).

constr

constraint function. For example, you can formulate \(x<=10\) as \(constr = function(x) return(x - 10)\).

c

the ratio of step-size and search distance d. $$d = \frac{step}{c}$$

l0

position jitter factor constant.Default = 0.

l1

initial position jitter factor.Default = 0.

eta_l

attenuation coefficient of jitter factor.$$l^t = \eta_l * l^{t-1} + l_0$$

step0

the minimal resolution of step-size

step

initial step-size of beetle.$$step = \eta_{step}(step-step0) + step0$$

eta_step

attenuation coefficient of step-size.$$step^t = \eta_{step} * step^{t-1}$$

n

iterations times

seed

random seed; default = NULL ; The results of BAS depend on random init value and random directions. Therefore, if you set a random seed, for example,seed = 1, the results will remain the same no matter how many times you repeat your experiments.

trace

default = T; trace the process of BAS iteration.

steptol

default = step0/2; Iteration will stop if step-size in current moment is less than steptol.

pen

penalty conefficient usually predefined as a large enough value, default 1e5

w0

inertia weight; default = 0.7

w1

weight of the difference between left and right antenae. default = 0.2 $$v = w_0v-w_1dir(f_{left}-f_{right})$$

c0

the ratio of maximal speed and initial step.$$v_{max} = c_0step$$

Value

A list including best beetle position (parameters) and corresponding objective function value.

Examples

#======== examples start ======================= # BAS application on Michalewicz function library(rBAS) mich <- function(x){ y1 <- -sin(x[1])*(sin((x[1]^2)/pi))^20 y2 <- -sin(x[2])*(sin((2*x[2]^2)/pi))^20 return(y1+y2) } fit<- BASoptim2(fn = mich, lower = c(-6,0), upper = c(-1,2), n = 100, trace = F, c = 0.4,#d = 1.2/0.4 = 3 step = 1.2, seed = 1, w0 = 0.4,w1 = 0.2, c0 = 0.6) fit$par;fit$value
#> [1] -4.965421 1.569728
#> [1] -1.967772
func1 <- function(x){ sum(x^2) } fit<- BASoptim2(fn = func1, lower = c(-100,-100), upper = c(100,100), n = 100, trace = F, c = 20, step = 100, seed = 1, w0 = 0.5,w1 = 0.2, c0 = 0.6) fit$par;fit$value
#> [1] 7.320204e-06 7.091455e-05
#> [1] 5.082459e-09
func2 <- function(x){ sum((abs(x)-5)^2) } fit<- BASoptim2(fn = func2, lower = c(-10,-10), upper = c(10,10), n = 100, trace = F, c = 5, step = 5, seed = 1, w0 = 0.2,w1 = 0.2, c0 = 0.6) fit$par;fit$value
#> [1] -5 -5
#> [1] 1.871564e-13
#======== examples end =======================