Swarm Intelligence (SI) is a branch of Artificial Intelligence based on the collective behavior of decentralized, self-organized systems — typically natural systems like ant colonies, bird flocks, or fish schools.
These systems show how simple agents (with limited intelligence) following simple rules can collectively perform complex tasks.
Decentralized: No central controller.
Self-organizing: The system organizes itself over time.
Scalable: Works well with large numbers of agents.
Robust: Can handle failure of individual agents.
Organism | Behavior Modeled |
---|---|
Ants | Foraging behavior (e.g., Ant Colony) |
Birds | Flocking behavior |
Fish | Schooling |
Bees | Foraging and communication (waggle dance) |
Termites | Nest building |
Inspired by ants finding the shortest path to food using pheromone trails.
* Used for:
Routing (like GPS)
Traveling Salesman Problem (TSP)
Network optimization
Inspired by birds flocking or fish schooling. Particles "fly" through the solution space to find optima.
* Used for:
Function optimization
Training neural networks
Hyperparameter tuning
Based on how bees search for nectar and communicate good food sources.
* Used for:
Resource allocation
Job scheduling
Initialize a population of agents (particles, ants, bees, etc.)
Evaluate fitness of each agent's solution.
Update agents' positions or decisions based on:
Their own experience
Information from nearby agents (neighbors)
Environmental feedback
Repeat until convergence or a stopping condition is met.
import numpy as np
# Objective Function (Minimize this)
def fitness(x):
return x**2 + 5*np.sin(x)
# Initialize particles
n_particles = 30
x = np.random.uniform(-10, 10, n_particles)
v = np.zeros(n_particles)
# PSO parameters
pbest = x.copy()
pbest_val = fitness(x)
gbest = pbest[np.argmin(pbest_val)]
w = 0.5 # inertia
c1 = c2 = 1.5 # cognitive and social coefficients
# PSO loop
for _ in range(100):
r1, r2 = np.random.rand(n_particles), np.random.rand(n_particles)
v = w*v + c1*r1*(pbest - x) + c2*r2*(gbest - x)
x = x + v
fit = fitness(x)
mask = fit < pbest_val
pbest[mask] = x[mask]
pbest_val[mask] = fit[mask]
gbest = pbest[np.argmin(pbest_val)]
print("Best solution:", gbest)
Robotics: Swarm robots (e.g., search and rescue)
Optimization Problems: Scheduling, resource allocation, routing
Machine Learning: Feature selection, hyperparameter tuning
Data Clustering
Game AI: Coordinated group behavior
Simple to implement
High fault tolerance
Flexible and adaptable
Slower convergence
May get stuck in local optima
Parameter tuning is often tricky.