Bat Algorithm (BAT)¶
A module for the bat optimization algorithm with differential operator, Levy flights trajectory, and parallel computing support.
Original papers:
Xie, J., Zhou, Y., Chen, H. (2013). A novel bat algorithm based on differential operator and Lévy flights trajectory. Computational intelligence and neuroscience, 2013.
Yang, X. S. (2010). A new metaheuristic bat-inspired algorithm. In Nature inspired cooperative strategies for optimization (NICSO 2010) (pp. 65-74). Springer, Berlin, Heidelberg.
What can you use?¶
Multi processing: ✔️
Discrete spaces: ✔️
Continuous spaces: ✔️
Mixed Discrete/Continuous spaces: ✔️
Parameters¶
-
class
neorl.evolu.bat.BAT(mode, bounds, fit, nbats=50, fmin=0, fmax=1, A=0.5, r0=0.5, alpha=1.0, gamma=0.9, levy='False', int_transform='nearest_int', ncores=1, seed=None)[source]¶ BAT Algorithm
- Parameters
mode – (str) problem type, either
minfor minimization problem ormaxfor maximizationbounds – (dict) input parameter type and lower/upper bounds in dictionary form. Example:
bounds={'x1': ['float', 0.1, 0.8], 'x2': ['float', 2.2, 6.2]}fit – (function) the fitness function
nbats – (int): number of bats in the population
fmin – (float): minimum value of the pulse frequency
fmax – (float): maximum value of the pulse frequency
A – (float) initial value of the loudness rate
r0 – (float) asymptotic value of the pulse rate
alpha – (float) decay factor of loudness
A, i.e. A approaches 0 by the end of evolution ifalpha < 1gamma – (float) exponential factor of the pulse rate
r, i.e.rincreases abruptly at the beginning and then converges tor0by the end of evolutionlevy – (bool): a flag to activate Levy flight steps of the bat to increase bat diversity
int_transform – (str): method of handling int/discrete variables, choose from:
nearest_int,sigmoid,minmax.ncores – (int) number of parallel processors (must be
<= nbats)seed – (int) random seed for sampling
-
evolute(ngen, x0=None, verbose=False)[source]¶ This function evolutes the BAT algorithm for number of generations.
- Parameters
ngen – (int) number of generations to evolute
x0 – (list of lists) initial position of the bats (must be of same size as
nbats)verbose – (bool) print statistics to screen
- Returns
(tuple) (best individual, best fitness, and dictionary containing major search results)
Example¶
from neorl import BAT
#Define the fitness function
def FIT(individual):
"""Sphere test objective function.
F(x) = sum_{i=1}^d xi^2
d=1,2,3,...
Range: [-100,100]
Minima: 0
"""
y=sum(x**2 for x in individual)
return y
#Setup the parameter space (d=5)
nx=5
BOUNDS={}
for i in range(1,nx+1):
BOUNDS['x'+str(i)]=['float', -100, 100]
#setup and evolute BAT
bat=BAT(mode='min', bounds=BOUNDS, fit=FIT, nbats=40,
fmin=0, fmax=1, A=1.0, r0=0.7,
ncores=1, seed=1)
x_best, y_best, bat_hist=bat.evolute(ngen=100, verbose=1)
Notes¶
BAT mimics the echolocation behavior of bats in nature. The bats emit a very loud and short sound pulse; the echo that reflects back from the surrounding objects is received by their big ears. This feedback information of echo is analyzed by the bats, which reveals the direction of the flight pathway. The echo also helps the bats to distinguish different insects and obstacles to hunt prey, where the search for the prey here is analogous to the search for global optima.
The bats start with loudness value of
A, and decay it by a factor ofalpha. If the user choosesalpha=1, fixed value ofAis used.Bats fly randomly to search for the prey with frequency varying between
fminandfmax.The bats emit pulses with emission rate represented by the asymptotic value (
r0). The value of emission rate is updated in generationiaccording to \(r_i = r_0(1-exp(-\gamma i))\), wheregammais the exponential factor of the pulse rate.rtypically decreases abruptly at the beginning and then converges back tor0by the end of the evolution.We provide a flexible BAT implemetation that can handle continuous (
float), discrete (int), and categorical (grid) spaces and their mix. The user can control the type of discrete transformation via the argumentint_transform.ncoresargument evaluates the fitness of all bats in parallel. Therefore, setncores <= nbatsfor most optimal resource allocation.Look for an optimal balance between
nbatsandngen, it is recommended to minimize the number ofnbatsto allow for more updates and more generations.Total number of cost evaluations for BAT is
3*nbats*(ngen + 1).