Animal and swarm-inspired algorithmsVerified

Moth-Flame Optimization

Moth-Flame Optimization (MFO)

Year introduced
2015
Original authors
Seyedali Mirjalili
Source of inspiration
Transverse orientation of moths around light sources
Search space
Continuous
Optimization types
Hyperparameter Optimization, Feature Selection
Applied research in the repository
1

Overview

The moths represent the current solutions and the flames the best saved solutions. Each moth spirals around a flame assigned to it, and the number of flames decreases gradually to increase exploitation.

Source of inspiration and mechanism

Image illustrating the source of inspiration of the MFO algorithm: Transverse orientation of moths around light sources
Transverse orientation of moths around light sourcesImage: Carlos Delgado · CC BY-SA 3.0 · Wikimedia Commons

Moths keep a fixed angle to the moon while flying at night, but they circle along a converging spiral around nearby artificial lights.

Initialization

Random moths.

Update mechanism

The moths and flames are merged and sorted in each iteration.

Exploration

t close to 1 gives larger distances around the flame.

Exploitation

Fewer flames and negative values of t.

Mathematical description

Spiral

S(M_i, F_j) = D_i\, e^{b t}\cos(2\pi t) + F_j,\quad D_i = |F_j - M_i|

t∈[r,1] and r decreases from −1 to −2.

Number of flames

\text{flame no} = \text{round}\left(N - l\frac{N-1}{T}\right)

Computational complexity: O(T\cdot N\log N + T\cdot N\cdot D)

Flowchart

StartInitialisationRandom mothsEvaluationCompute the objective and find the bestsolutiont ≤ T ?Explorationt close to 1 gives larger distances aroundthe flameExploitationFewer flames and negative values of tUpdate ruleThe moths and flames are merged and sortedin each iterationUpdate bestKeep the best solution and set t = t + 1EndReturn the best solutionYesNo

A simplified chart summarising the algorithm phases as described on its card in the lab; it is not the original figure published in the paper.

Pseudocode

Initialize moths M; flames F = sorted(M)
for l = 1..T:
    update flame number; r decreases from -1 to -2
    for each moth i: assign flame j = min(i, flame_no); move by spiral
    F = best N of (F ∪ M)
return F[0]

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 mfo(f, lb, ub, dim, n=30, iters=200, b=1.0, seed=0):
    """Moth-Flame Optimization (Mirjalili, 2015): logarithmic spiral around a shrinking set of flames."""
    rng = np.random.default_rng(seed)
    moth = rng.uniform(lb, ub, (n, dim)); Fm = np.apply_along_axis(f, 1, moth)
    order = np.argsort(Fm); flames, Ff = moth[order].copy(), Fm[order].copy()
    curve = []
    for t in range(1, iters + 1):
        nflames = round(n - t * (n - 1) / iters)
        a = -1 + t * (-1 / iters)                             # decreases from -1 to -2
        for i in range(n):
            j = min(i, nflames - 1)
            D = np.abs(flames[j] - moth[i])
            tt = (a - 1) * rng.random(dim) + 1
            moth[i] = D * np.exp(b * tt) * np.cos(2 * np.pi * tt) + flames[j]
        moth = np.clip(moth, lb, ub); Fm = np.apply_along_axis(f, 1, moth)
        allx = np.vstack([flames, moth]); allf = np.concatenate([Ff, Fm])
        order = np.argsort(allf)[:n]; flames, Ff = allx[order], allf[order]
        curve.append(Ff[0])
    return flames[0], Ff[0], curve

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

Coefficients

ParameterSymbolTypical valueRangeDescription
Spiral constant
b
1
Population
N
30

Advantages

  • Few parameters
  • Explicitly keeps the best solutions.

Limitations

Reducing the flames may cause premature convergence.

Use in artificial intelligence

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

Continuous optimization, engineering design, parameter tuning.

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

Original reference

Seyedali Mirjalili (2015). Moth-flame optimization algorithm: A novel nature-inspired heuristic paradigm. Knowledge-Based Systems, Elsevier BV.

Verified DOI: 10.1016/j.knosys.2015.07.006