Animal and swarm-inspired algorithmsVerified

Artificial Bee Colony

Artificial Bee Colony (ABC)

Year introduced
2007
Original authors
Dervis Karaboga; Bahriye Basturk
Source of inspiration
The nectar foraging behaviour of honey bees
Search space
Continuous
Optimization types
Hyperparameter Optimization, Feature Selection, Weight Optimization
Applied research in the repository
1

Overview

Each food source is a candidate solution. The employed bee runs a neighbourhood search by changing one dimension, the onlooker chooses sources probabilistically by their quality, and the scout replaces a source that has not improved after limit trials.

Source of inspiration and mechanism

Image illustrating the source of inspiration of the ABC algorithm: The nectar foraging behaviour of honey bees
The nectar foraging behaviour of honey beesImage: Andreas Trepte · CC BY-SA 2.5 · Wikimedia Commons

The colony shares three roles: employed bees that exploit known food sources, onlooker bees that choose sources from the dances of the employed bees, and scout bees that search randomly for new sources when a source is exhausted.

Initialization

Uniform random food sources.

Update mechanism

One dimension is changed at a time with greedy selection; the trial counter.

Exploration

The scout phase and the reinitialization of exhausted sources.

Exploitation

The employed and onlooker phases around the good sources.

Mathematical description

The proposed neighbour changes one dimension towards or away from another random source, and is accepted by greedy selection.

Neighbour solution

v_{ij} = x_{ij} + \phi_{ij}\,(x_{ij} - x_{kj}),\quad \phi_{ij}\sim U(-1,1)

k≠i random, j a random dimension.

Onlooker selection probability

p_i = \frac{fit_i}{\sum_{n=1}^{SN} fit_n},\quad fit_i = \begin{cases}\frac{1}{1+f_i} & f_i\ge 0\\ 1+|f_i| & f_i<0\end{cases}

Scout

x_{ij} = lb_j + U(0,1)\,(ub_j - lb_j)\quad \text{if } trial_i > limit

Computational complexity: O(T\cdot SN\cdot (D + C_f))

Pseudocode

Initialize SN food sources; trial = 0
for t = 1..T:
    Employed phase: for each source i, create v_i; greedy select
    compute p_i ; Onlooker phase: choose sources by p_i, create v, greedy select
    Scout phase: if trial_i > limit: reinitialize source i
    remember best
return best

Python 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 abc(f, lb, ub, dim, food=20, iters=200, limit=None, seed=0):
    """Artificial Bee Colony (Karaboga & Basturk, 2007): employed, onlooker and scout phases."""
    rng = np.random.default_rng(seed)
    limit = limit or food * dim
    X = rng.uniform(lb, ub, (food, dim))
    F = np.apply_along_axis(f, 1, X)
    trial = np.zeros(food, int)
    fitness = lambda v: 1 / (1 + v) if v >= 0 else 1 + abs(v)
    best = X[F.argmin()].copy(); bval = F.min(); curve = []

    def try_neighbour(i):
        nonlocal best, bval
        k = rng.choice([j for j in range(food) if j != i])
        d = rng.integers(dim)
        v = X[i].copy()
        v[d] = np.clip(X[i, d] + rng.uniform(-1, 1) * (X[i, d] - X[k, d]), lb, ub)
        fv = f(v)
        if fv < F[i]:                       # greedy selection
            X[i], F[i], trial[i] = v, fv, 0
        else:
            trial[i] += 1

    for _ in range(iters):
        for i in range(food):               # employed bees
            try_neighbour(i)
        fit = np.array([fitness(v) for v in F]); prob = fit / fit.sum()
        for _ in range(food):               # onlooker bees
            try_neighbour(rng.choice(food, p=prob))
        worst = trial.argmax()              # scout bee
        if trial[worst] > limit:
            X[worst] = rng.uniform(lb, ub, dim); F[worst] = f(X[worst]); trial[worst] = 0
        if F.min() < bval:
            bval = F.min(); best = X[F.argmin()].copy()
        curve.append(bval)
    return best, bval, curve

if __name__ == "__main__":
    sphere = lambda z: float(np.sum(z ** 2))
    best, val, curve = abc(sphere, -100, 100, dim=10)
    print("best fitness:", val)

Coefficients

ParameterSymbolTypical valueRangeDescription
Food sources
SN
2010 – 50Half of the colony
Abandonment limit
limit
SN·D50 – 500Number of trials before abandonment

Advantages

  • limit
  • Good exploration
  • Stable on multimodal functions.

Limitations

  • Slow exploitation because each update changes one dimension
  • Slower convergence in high dimensions.

Use in artificial intelligence

Domains documented in the card: Machine learning, deep learning, Feature Selection, hyperparameter tuning

Continuous optimization, training small networks, clustering, feature selection with the binary versions.

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

Related lessons

Original reference

Dervis Karaboga; Bahriye Basturk (2007). A powerful and efficient algorithm for numerical function optimization: artificial bee colony (ABC) algorithm. Journal of Global Optimization, Springer Science and Business Media LLC.

Verified DOI: 10.1007/s10898-007-9149-x