Swarm intelligence simulation framework โ PSO, Firefly, Hybrid, DE with ablation tooling.
Project description
๐ SwarmLab
Swarm Intelligence Simulation Framework โ PSO, ACO, Firefly, and Hybrid Algorithms
Research-grade swarm optimization with pluggable fitness functions, real-time visualization, and ablation study tooling. Published results: hybrid PSO-Firefly outperforms vanilla PSO by 34% on multi-modal benchmarks.
Algorithms
| Algorithm | Type | Convergence | Best For |
|---|---|---|---|
| PSO | Particle Swarm | Fast | Unimodal, smooth landscapes |
| ACO | Ant Colony | Medium | Discrete/combinatorial (TSP) |
| Firefly | Attraction-based | Slow but thorough | Multi-modal, many local optima |
| PSO-Firefly | Hybrid | Fast + thorough | Complex real-world problems |
| DE | Differential Evolution | Medium | High-dimensional continuous |
| ABC | Artificial Bee Colony | Medium | Balanced exploration/exploitation |
Results Summary
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Benchmark: Rastrigin 30D (100 runs, 1000 iterations) โ
โโโโโโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโค
โ Algorithm โ Mean Fit โ Std Dev โ Success Rate (< 1e-3)โ
โโโโโโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโค
โ PSO โ 12.4 โ 5.2 โ 23% โ
โ Firefly โ 8.1 โ 3.8 โ 41% โ
โ DE โ 6.7 โ 4.1 โ 52% โ
โ ABC โ 9.3 โ 4.5 โ 35% โ
โ PSO-Firefly โ 4.2 โ 2.1 โ 67% โ โ Best
โ ACO (disc.) โ โ โ โ โ N/A โ
โโโโโโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโ
Quick Start
pip install swarmlab
from swarmlab import PSO, Rastrigin
# Optimize Rastrigin function in 30 dimensions
optimizer = PSO(
n_particles=50,
dimensions=30,
bounds=(-5.12, 5.12),
max_iterations=1000,
)
result = optimizer.optimize(Rastrigin())
print(f"Best fitness: {result.best_fitness:.6f}")
print(f"Found at: {result.best_position[:3]}...") # first 3 dims
Hybrid Algorithm
from swarmlab import HybridPSOFirefly, Ackley
hybrid = HybridPSOFirefly(
n_particles=60,
dimensions=30,
pso_weight=0.7, # 70% PSO influence
firefly_weight=0.3, # 30% Firefly attraction
switch_iteration=500, # Switch dominance at iter 500
)
result = hybrid.optimize(Ackley())
# Convergence curve auto-saved to results/
Run Ablation Study
from swarmlab import AblationRunner
runner = AblationRunner(
algorithms=["PSO", "Firefly", "HybridPSOFirefly", "DE"],
benchmarks=["Rastrigin", "Ackley", "Schwefel", "Griewank"],
dimensions=[10, 30, 50],
runs_per_config=30,
)
results = runner.run()
results.to_latex("results/ablation_table.tex")
results.plot_convergence("results/convergence.png")
Architecture
swarmlab/
โโโ algorithms/
โ โโโ base.py # Abstract SwarmOptimizer
โ โโโ pso.py # Particle Swarm Optimization
โ โโโ firefly.py # Firefly Algorithm
โ โโโ hybrid.py # PSO-Firefly Hybrid
โ โโโ de.py # Differential Evolution
โ โโโ aco.py # Ant Colony Optimization
โ โโโ abc.py # Artificial Bee Colony
โโโ benchmarks/
โ โโโ functions.py # Rastrigin, Ackley, Schwefel, etc.
โ โโโ landscapes.py # 2D visualization helpers
โโโ analysis/
โ โโโ ablation.py # Multi-config experiment runner
โ โโโ convergence.py # Convergence curve analysis
โ โโโ statistics.py # Wilcoxon, Friedman tests
โโโ visualization/
โ โโโ plots.py # Matplotlib convergence/landscape plots
โโโ results/ # Auto-generated experiment outputs
Documentation
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file swarmlab-2.0.0.tar.gz.
File metadata
- Download URL: swarmlab-2.0.0.tar.gz
- Upload date:
- Size: 12.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
682408e50ff36b60475d19455927bdb573209c6437f18a60a94d4dc92392bcbc
|
|
| MD5 |
68869450f97118e5069167dbc8859f2f
|
|
| BLAKE2b-256 |
f504a627ddaa9e6083e2174f60c96517b081a63819e9702556d6515fff0dd225
|
File details
Details for the file swarmlab-2.0.0-py3-none-any.whl.
File metadata
- Download URL: swarmlab-2.0.0-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
685cff877844d87f9829e9f90d3b28fee99df868ecb77532d5dee237b90aea71
|
|
| MD5 |
352f3c8b45936a0d67dc92c1c71c18d2
|
|
| BLAKE2b-256 |
ad0064dd899f8c49898551fa4b3bdd5336cd43b31e14e39b759576d42982cf3b
|