Physics and chemistry-inspired algorithmsVerified

Gravitational Search Algorithm

Gravitational Search Algorithm (GSA)

Year introduced
2009
Original authors
Esmat Rashedi; Hossein Nezamabadi-pour; Saeid Saryazdi
Source of inspiration
Newton's law of universal gravitation
Search space
Continuous
Optimization types
Hyperparameter Optimization, Feature Selection
Applied research in the repository
0

Overview

Each agent's mass is computed from its fitness, and forces from the Kbest best agents act on it so that it accelerates towards them. The gravitational constant G and the number of influential agents decrease over time.

Source of inspiration and mechanism

Image illustrating the source of inspiration of the GSA algorithm: Newton's law of universal gravitation
Newton's law of universal gravitationImage: NASA, ESA, and the Hubble Heritage Team (STScI/AURA) · Public domain · Wikimedia Commons

Masses attract each other with a force proportional to the product of the two masses, so light masses move towards heavy ones. In GSA the mass represents the quality of the solution.

Initialization

Random with zero velocity.

Update mechanism

Movement based on collective acceleration.

Exploration

A large Kbest and a high G at the start.

Exploitation

Kbest shrinks to a single agent, and G decreases.

Mathematical description

The formula shown divides by the distance R and not R² as in the original paper, which found that R gives better results.

Mass

m_i = \frac{fit_i - worst}{best - worst},\quad M_i = \frac{m_i}{\sum_j m_j}

Force

F_{ij}^{d} = G(t)\frac{M_i M_j}{R_{ij}+\epsilon}\left(x_j^{d} - x_i^{d}\right)

Acceleration and motion

a_i^{d} = \sum_{j\in Kbest, j\ne i} r_j F_{ij}^{d}/M_i,\quad v_i^{d} \leftarrow r_i v_i^{d} + a_i^{d},\quad x_i^{d} \leftarrow x_i^{d} + v_i^{d}

Gravitational constant

G(t) = G_0\, e^{-\alpha t/T}

Computational complexity: O(T\cdot N^{2}\cdot D)

Pseudocode

Initialize agents
for t = 1..T:
    evaluate; compute masses; G = G0*exp(-alpha*t/T); Kbest shrinks
    compute accelerations from Kbest agents
    update velocities and positions
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 gsa(f, lb, ub, dim, n=30, iters=200, G0=100.0, alpha=20.0, seed=0):
    """Gravitational Search Algorithm (Rashedi et al., 2009) with the Kbest schedule."""
    rng = np.random.default_rng(seed)
    X = rng.uniform(lb, ub, (n, dim)); V = np.zeros((n, dim))
    best, bval, curve = None, np.inf, []
    for t in range(iters):
        F = np.apply_along_axis(f, 1, X)
        if F.min() < bval: bval, best = F.min(), X[F.argmin()].copy()
        worst, bst = F.max(), F.min()
        m = (F - worst) / (bst - worst) if bst != worst else np.ones(n)
        M = m / m.sum()
        G = G0 * np.exp(-alpha * t / iters)
        kbest = int(round(n - (n - 1) * t / iters))           # fewer attractors over time
        top = np.argsort(F)[:kbest]
        acc = np.zeros((n, dim))
        for i in range(n):
            for j in top:
                if j == i: continue
                R = np.linalg.norm(X[i] - X[j])
                acc[i] += rng.random(dim) * G * M[j] * (X[j] - X[i]) / (R + 1e-12)
        V = rng.random((n, dim)) * V + acc
        X = np.clip(X + V, lb, ub)
        curve.append(bval)
    return best, bval, curve

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

Coefficients

ParameterSymbolTypical valueRangeDescription
G₀
G₀
100
Decay
α
20
Agents
N
30

Advantages

  • Collective memory across blocks
  • Good performance on unimodal functions.

Limitations

  • Quadratic cost
  • Loss of diversity as kbest. shrinks

Use in artificial intelligence

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

Continuous optimization, clustering, feature selection with the binary version.

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

An aspect that did not appear in the current search results within the repository. This does not mean there is no published research outside it.

Original reference

Esmat Rashedi; Hossein Nezamabadi-pour; Saeid Saryazdi (2009). GSA: A Gravitational Search Algorithm. Information Sciences, Elsevier BV.

Verified DOI: 10.1016/j.ins.2009.03.004