Bat Algorithm
Bat Algorithm (BA)
- Year introduced
- 2010
- Original authors
- Xin-She Yang
- Source of inspiration
- Echolocation in bats
- Search space
- Continuous
- Optimization types
- Hyperparameter Optimization, Feature Selection
- Applied research in the repository
- 3
Overview
BA combines a PSO-like velocity update with a random frequency, a local search around the best solution triggered by the pulse rate r, and acceptance of new solutions based on the loudness A.
Source of inspiration and mechanism

Microbats emit sound pulses at different frequencies, increasing the pulse rate and lowering the loudness as they approach their prey.
Initialization
Random positions and zero velocities, a high A₀ and a low r₀.
Update mechanism
Probabilistic acceptance conditioned on improvement and loudness.
Exploration
Random frequencies and high loudness at the start.
Exploitation
Local search around the best solution as r increases.
Mathematical description
Frequency and velocity
f_i = f_{min} + (f_{max}-f_{min})\beta,\quad v_i^{t} = v_i^{t-1} + (x_i^{t} - x^{*}) f_iβ∼U(0,1).
Position
x_i^{t} = x_i^{t-1} + v_i^{t}Local search
x_{new} = x_{old} + \epsilon\, \bar A^{t},\ \epsilon\sim U(-1,1)Ā is the average loudness.
Loudness and pulse update
A_i^{t+1} = \alpha A_i^{t},\quad r_i^{t+1} = r_i^{0}\left[1 - e^{-\gamma t}\right]Computational complexity: O(T\cdot N\cdot (D + C_f))
Pseudocode
Initialize bats x_i, v_i, A_i, r_i
for t = 1..T:
for each bat: draw frequency, update v_i and x_i
if rand > r_i: x = local walk around best
if rand < A_i and f(x) < f(x_i): accept; A_i *= alpha; increase r_i
update best
return bestPython implementation
This code was actually run while building the lab (NumPy) on the sphere function to make sure it works; this is a run test, not a performance claim.
import numpy as np
def bat(f, lb, ub, dim, n=30, iters=200, fmin=0.0, fmax=2.0, A0=0.9, r0=0.5, alpha=0.9, gamma=0.9, seed=0):
"""Bat Algorithm (Yang, 2010): frequency-tuned velocities, loudness A and pulse rate r."""
rng = np.random.default_rng(seed)
x = rng.uniform(lb, ub, (n, dim)); v = np.zeros((n, dim))
F = np.apply_along_axis(f, 1, x)
A = np.full(n, A0); r = np.zeros(n)
best = x[F.argmin()].copy(); bval = F.min(); curve = []
for t in range(1, iters + 1):
for i in range(n):
freq = fmin + (fmax - fmin) * rng.random()
v[i] = v[i] + (x[i] - best) * freq
cand = np.clip(x[i] + v[i], lb, ub)
if rng.random() > r[i]: # local random walk around the best
cand = np.clip(best + 0.01 * (ub - lb) * A.mean() * rng.normal(size=dim), lb, ub)
fc = f(cand)
if fc <= F[i] and rng.random() < A[i]:
x[i], F[i] = cand, fc
A[i] *= alpha; r[i] = r0 * (1 - np.exp(-gamma * t))
if fc < bval:
bval, best = fc, cand.copy()
curve.append(bval)
return best, bval, curve
if __name__ == "__main__":
sphere = lambda z: float(np.sum(z ** 2))
best, val, curve = bat(sphere, -100, 100, dim=10)
print("best fitness:", val)
Coefficients
| Parameter | Symbol | Typical value | Range | Description |
|---|---|---|---|---|
| Frequency range | f_min,f_max | 0, 2 | Frequency range | |
| Loudness | A₀ | 0.9 | 0.5 – 1 | Initial acceptance probability |
| Pulse rate | r₀ | 0.5 | ||
| Decay | α, γ | 0.9, 0.9 | The two rates of change |
Advantages
Automatic balance between exploration and exploitation through A and r.
Limitations
- Relatively many parameters
- May converge prematurely when the intensity drops quickly.
Use in artificial intelligence
Domains documented in the card: Machine learning, Feature Selection, hyperparameter tuning
Continuous optimization, engineering design, feature selection with the binary version.
Related models in the relationship table
- U-Net — Hyperparameter optimization Published result
Hybridization potential
These are partnerships suggested theoretically in the card; any resulting design is presented as a "proposed hybrid method" until its results are compared with the literature.
Applied research from the repository
- Enhanced Liver Tumor Detection in CT Images Using 3D U-Net and Bat Algorithm for Hyperparameter Optimization Partially verified
- Exposing the grey wolf, moth-flame, whale, firefly, bat, and antlion algorithms: six misleading optimization techniques inspired by bestial metaphors Verified
- Grey Wolf, Firefly and Bat Algorithms: Three Widespread Algorithms that Do Not Contain Any Novelty Verified
Original reference
Xin-She Yang (2010). A New Metaheuristic Bat-Inspired Algorithm. Studies in Computational Intelligence (NICSO 2010), Springer Berlin Heidelberg.
Verified DOI: 10.1007/978-3-642-12538-6_6
