You could find more information about BAS in https://arxiv.org/abs/1710.10724.

BASoptim(fn, init = NULL, lower = c(-6, 0), upper = c(-1, 2),
  constr = NULL, d0 = 0.001, d1 = 3, eta_d = 0.95, l0 = 0,
  l1 = 0, eta_l = 0.95, step = 0.8, eta_step = 0.95, n = 200,
  seed = NULL, trace = T, steptol = 0.01, pen = 1e+05)

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)\).

d0

a constant to gurantee that sensing length of antennae d doesn't equal to zero. More specifically, $$d^t = \eta_d * d^{t-1} + d_0$$where attenuation coefficient \(\eta_d\) belongs to \([0,1]\)

d1

initial value of antenae length. You can specify it according to your problem scale

eta_d

attenuation coefficient of sensing length of antennae

l0

position jitter factor constant.Default = 0.

l1

initial position jitter factor.Default = 0.$$x = x - step * dir * sign(fn(left) - fn(right)) + l *random(npars)$$

eta_l

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

step

initial step-size of beetle

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 = 0.01; 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

Value

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

References

X. Y. Jiang, and S. Li, BAS: beetle antennae search algorithm for optimization problems, arXiv:1710.10724v1.

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) } BASoptim(fn = mich, lower = c(-6,0), upper = c(-1,2), seed = 1, n = 100,trace = FALSE)
#> $par #> [1] -4.964687 1.575415 #> #> $value #> [1] -1.966817 #> #> $df #> $df$x #> [,1] [,2] #> [1,] -4.672457 0.7442478 #> [2,] -4.813013 0.0000000 #> [3,] -5.527720 0.0000000 #> [4,] -5.042063 0.5342482 #> [5,] -5.727938 0.5400962 #> [6,] -5.986547 1.1381854 #> [7,] -5.754145 0.5644425 #> [8,] -6.000000 0.4262851 #> [9,] -6.000000 0.9761205 #> [10,] -6.000000 0.7332715 #> [11,] -6.000000 0.9191553 #> [12,] -6.000000 0.8309048 #> [13,] -6.000000 0.8091928 #> [14,] -5.973267 0.3777321 #> [15,] -5.672984 0.6578803 #> [16,] -6.000000 0.8523803 #> [17,] -6.000000 0.4923300 #> [18,] -5.971725 0.1413658 #> [19,] -6.000000 0.4436146 #> [20,] -6.000000 0.7608100 #> [21,] -5.844291 1.0194368 #> [22,] -5.986800 0.7705616 #> [23,] -6.000000 1.0084710 #> [24,] -6.000000 0.7855828 #> [25,] -5.831769 0.9649089 #> [26,] -5.610446 1.0396157 #> [27,] -5.704229 1.2407364 #> [28,] -5.493779 1.2531614 #> [29,] -5.313706 1.3408183 #> [30,] -5.202284 1.4950410 #> [31,] -5.137577 1.3262720 #> [32,] -5.129357 1.4977862 #> [33,] -5.123131 1.3347795 #> [34,] -5.096117 1.1821831 #> [35,] -4.952607 1.2150267 #> [36,] -4.812764 1.2172297 #> [37,] -4.715281 1.3075096 #> [38,] -4.815805 1.3838449 #> [39,] -4.708492 1.4373493 #> [40,] -4.708649 1.5512657 #> [41,] -4.774865 1.4656668 #> [42,] -4.794253 1.5666318 #> [43,] -4.885639 1.5321651 #> [44,] -4.918816 1.4455136 #> [45,] -4.944315 1.5298912 #> [46,] -4.965481 1.4488712 #> [47,] -4.885932 1.4495587 #> [48,] -4.828910 1.4991568 #> [49,] -4.892487 1.5325133 #> [50,] -4.955420 1.5588091 #> [51,] -4.990486 1.6132961 #> [52,] -4.986023 1.5519021 #> [53,] -4.976262 1.4942444 #> [54,] -5.018245 1.5306271 #> [55,] -5.063467 1.5578353 #> [56,] -5.016184 1.5411596 #> [57,] -4.968630 1.5384521 #> [58,] -4.947303 1.5783600 #> [59,] -4.963763 1.5386494 #> [60,] -4.984243 1.5739802 #> [61,] -4.952040 1.5956150 #> [62,] -4.924247 1.5714097 #> [63,] -4.930914 1.5370373 #> [64,] -4.948135 1.5085799 #> [65,] -4.946924 1.5401559 #> [66,] -4.955350 1.5689682 #> [67,] -4.972780 1.5915403 #> [68,] -4.949393 1.5778636 #> [69,] -4.968590 1.5607196 #> [70,] -4.955205 1.5811813 #> [71,] -4.953265 1.5580340 #> [72,] -4.974197 1.5650203 #> [73,] -4.964567 1.5836411 #> [74,] -4.976438 1.5676503 #> [75,] -4.975715 1.5865561 #> [76,] -4.962715 1.5741438 #> [77,] -4.965944 1.5573769 #> [78,] -4.977597 1.5686617 #> [79,] -4.965882 1.5786735 #> [80,] -4.951246 1.5789878 #> [81,] -4.964687 1.5754152 #> [82,] -4.962219 1.5624354 #> [83,] -4.971532 1.5540205 #> [84,] -4.960556 1.5493620 #> [85,] -4.971337 1.5458866 #> [86,] -4.969484 1.5564873 #> [87,] -4.972982 1.5660937 #> #> $df$f #> [,1] #> [1,] -6.583555e-05 #> [2,] -9.012505e-02 #> [3,] -1.936756e-11 #> [4,] -5.335012e-01 #> [5,] -2.113946e-02 #> [6,] -5.268663e-02 #> [7,] -5.829834e-02 #> [8,] -3.002182e-02 #> [9,] -3.003269e-02 #> [10,] -3.002182e-02 #> [11,] -3.002305e-02 #> [12,] -3.002184e-02 #> [13,] -3.002183e-02 #> [14,] -8.003364e-02 #> [15,] -1.078080e-03 #> [16,] -3.002189e-02 #> [17,] -3.002182e-02 #> [18,] -8.403287e-02 #> [19,] -3.002182e-02 #> [20,] -3.002182e-02 #> [21,] -3.647649e-01 #> [22,] -5.032884e-02 #> [23,] -3.005617e-02 #> [24,] -3.002182e-02 #> [25,] -3.262917e-01 #> [26,] -1.038747e-04 #> [27,] -2.987259e-02 #> [28,] -3.000103e-02 #> [29,] -1.493098e-01 #> [30,] -8.020784e-01 #> [31,] -1.565388e-01 #> [32,] -8.663391e-01 #> [33,] -2.025392e-01 #> [34,] -1.665101e-01 #> [35,] -9.636234e-01 #> [36,] -1.031007e-01 #> [37,] -8.668871e-02 #> [38,] -3.763027e-01 #> [39,] -5.128581e-01 #> [40,] -9.856311e-01 #> [41,] -6.785693e-01 #> [42,] -1.046880e+00 #> [43,] -1.450188e+00 #> [44,] -1.327901e+00 #> [45,] -1.859384e+00 #> [46,] -1.537935e+00 #> [47,] -1.083530e+00 #> [48,] -9.645447e-01 #> [49,] -1.507677e+00 #> [50,] -1.951293e+00 #> [51,] -1.838497e+00 #> [52,] -1.915277e+00 #> [53,] -1.754647e+00 #> [54,] -1.670970e+00 #> [55,] -1.353486e+00 #> [56,] -1.714509e+00 #> [57,] -1.926488e+00 #> [58,] -1.932233e+00 #> [59,] -1.927157e+00 #> [60,] -1.935480e+00 #> [61,] -1.924108e+00 #> [62,] -1.813102e+00 #> [63,] -1.811574e+00 #> [64,] -1.797196e+00 #> [65,] -1.896592e+00 #> [66,] -1.956776e+00 #> [67,] -1.945876e+00 #> [68,] -1.939454e+00 #> [69,] -1.963119e+00 #> [70,] -1.952225e+00 #> [71,] -1.945727e+00 #> [72,] -1.959980e+00 #> [73,] -1.960937e+00 #> [74,] -1.956888e+00 #> [75,] -1.948586e+00 #> [76,] -1.966350e+00 #> [77,] -1.960644e+00 #> [78,] -1.954642e+00 #> [79,] -1.965327e+00 #> [80,] -1.944244e+00 #> [81,] -1.966817e+00 #> [82,] -1.963652e+00 #> [83,] -1.953657e+00 #> [84,] -1.946783e+00 #> [85,] -1.940636e+00 #> [86,] -1.958484e+00 #> [87,] -1.962220e+00 #> #> $df$xbest #> [,1] [,2] #> [1,] -4.672457 0.7442478 #> [2,] -4.813013 0.0000000 #> [3,] -4.813013 0.0000000 #> [4,] -5.042063 0.5342482 #> [5,] -5.042063 0.5342482 #> [6,] -5.042063 0.5342482 #> [7,] -5.042063 0.5342482 #> [8,] -5.042063 0.5342482 #> [9,] -5.042063 0.5342482 #> [10,] -5.042063 0.5342482 #> [11,] -5.042063 0.5342482 #> [12,] -5.042063 0.5342482 #> [13,] -5.042063 0.5342482 #> [14,] -5.042063 0.5342482 #> [15,] -5.042063 0.5342482 #> [16,] -5.042063 0.5342482 #> [17,] -5.042063 0.5342482 #> [18,] -5.042063 0.5342482 #> [19,] -5.042063 0.5342482 #> [20,] -5.042063 0.5342482 #> [21,] -5.042063 0.5342482 #> [22,] -5.042063 0.5342482 #> [23,] -5.042063 0.5342482 #> [24,] -5.042063 0.5342482 #> [25,] -5.042063 0.5342482 #> [26,] -5.042063 0.5342482 #> [27,] -5.042063 0.5342482 #> [28,] -5.042063 0.5342482 #> [29,] -5.042063 0.5342482 #> [30,] -5.202284 1.4950410 #> [31,] -5.202284 1.4950410 #> [32,] -5.129357 1.4977862 #> [33,] -5.129357 1.4977862 #> [34,] -5.129357 1.4977862 #> [35,] -4.952607 1.2150267 #> [36,] -4.952607 1.2150267 #> [37,] -4.952607 1.2150267 #> [38,] -4.952607 1.2150267 #> [39,] -4.952607 1.2150267 #> [40,] -4.708649 1.5512657 #> [41,] -4.708649 1.5512657 #> [42,] -4.794253 1.5666318 #> [43,] -4.885639 1.5321651 #> [44,] -4.885639 1.5321651 #> [45,] -4.944315 1.5298912 #> [46,] -4.944315 1.5298912 #> [47,] -4.944315 1.5298912 #> [48,] -4.944315 1.5298912 #> [49,] -4.944315 1.5298912 #> [50,] -4.955420 1.5588091 #> [51,] -4.955420 1.5588091 #> [52,] -4.955420 1.5588091 #> [53,] -4.955420 1.5588091 #> [54,] -4.955420 1.5588091 #> [55,] -4.955420 1.5588091 #> [56,] -4.955420 1.5588091 #> [57,] -4.955420 1.5588091 #> [58,] -4.955420 1.5588091 #> [59,] -4.955420 1.5588091 #> [60,] -4.955420 1.5588091 #> [61,] -4.955420 1.5588091 #> [62,] -4.955420 1.5588091 #> [63,] -4.955420 1.5588091 #> [64,] -4.955420 1.5588091 #> [65,] -4.955420 1.5588091 #> [66,] -4.955350 1.5689682 #> [67,] -4.955350 1.5689682 #> [68,] -4.955350 1.5689682 #> [69,] -4.968590 1.5607196 #> [70,] -4.968590 1.5607196 #> [71,] -4.968590 1.5607196 #> [72,] -4.968590 1.5607196 #> [73,] -4.968590 1.5607196 #> [74,] -4.968590 1.5607196 #> [75,] -4.968590 1.5607196 #> [76,] -4.962715 1.5741438 #> [77,] -4.962715 1.5741438 #> [78,] -4.962715 1.5741438 #> [79,] -4.962715 1.5741438 #> [80,] -4.962715 1.5741438 #> [81,] -4.964687 1.5754152 #> [82,] -4.964687 1.5754152 #> [83,] -4.964687 1.5754152 #> [84,] -4.964687 1.5754152 #> [85,] -4.964687 1.5754152 #> [86,] -4.964687 1.5754152 #> [87,] -4.964687 1.5754152 #> #> $df$fbest #> [,1] #> [1,] -6.583555e-05 #> [2,] -9.012505e-02 #> [3,] -9.012505e-02 #> [4,] -5.335012e-01 #> [5,] -5.335012e-01 #> [6,] -5.335012e-01 #> [7,] -5.335012e-01 #> [8,] -5.335012e-01 #> [9,] -5.335012e-01 #> [10,] -5.335012e-01 #> [11,] -5.335012e-01 #> [12,] -5.335012e-01 #> [13,] -5.335012e-01 #> [14,] -5.335012e-01 #> [15,] -5.335012e-01 #> [16,] -5.335012e-01 #> [17,] -5.335012e-01 #> [18,] -5.335012e-01 #> [19,] -5.335012e-01 #> [20,] -5.335012e-01 #> [21,] -5.335012e-01 #> [22,] -5.335012e-01 #> [23,] -5.335012e-01 #> [24,] -5.335012e-01 #> [25,] -5.335012e-01 #> [26,] -5.335012e-01 #> [27,] -5.335012e-01 #> [28,] -5.335012e-01 #> [29,] -5.335012e-01 #> [30,] -8.020784e-01 #> [31,] -8.020784e-01 #> [32,] -8.663391e-01 #> [33,] -8.663391e-01 #> [34,] -8.663391e-01 #> [35,] -9.636234e-01 #> [36,] -9.636234e-01 #> [37,] -9.636234e-01 #> [38,] -9.636234e-01 #> [39,] -9.636234e-01 #> [40,] -9.856311e-01 #> [41,] -9.856311e-01 #> [42,] -1.046880e+00 #> [43,] -1.450188e+00 #> [44,] -1.450188e+00 #> [45,] -1.859384e+00 #> [46,] -1.859384e+00 #> [47,] -1.859384e+00 #> [48,] -1.859384e+00 #> [49,] -1.859384e+00 #> [50,] -1.951293e+00 #> [51,] -1.951293e+00 #> [52,] -1.951293e+00 #> [53,] -1.951293e+00 #> [54,] -1.951293e+00 #> [55,] -1.951293e+00 #> [56,] -1.951293e+00 #> [57,] -1.951293e+00 #> [58,] -1.951293e+00 #> [59,] -1.951293e+00 #> [60,] -1.951293e+00 #> [61,] -1.951293e+00 #> [62,] -1.951293e+00 #> [63,] -1.951293e+00 #> [64,] -1.951293e+00 #> [65,] -1.951293e+00 #> [66,] -1.956776e+00 #> [67,] -1.956776e+00 #> [68,] -1.956776e+00 #> [69,] -1.963119e+00 #> [70,] -1.963119e+00 #> [71,] -1.963119e+00 #> [72,] -1.963119e+00 #> [73,] -1.963119e+00 #> [74,] -1.963119e+00 #> [75,] -1.963119e+00 #> [76,] -1.966350e+00 #> [77,] -1.966350e+00 #> [78,] -1.966350e+00 #> [79,] -1.966350e+00 #> [80,] -1.966350e+00 #> [81,] -1.966817e+00 #> [82,] -1.966817e+00 #> [83,] -1.966817e+00 #> [84,] -1.966817e+00 #> [85,] -1.966817e+00 #> [86,] -1.966817e+00 #> [87,] -1.966817e+00 #> #>
#======== examples end =======================