Skip to main content
SwarmLab

🐝 SwarmLab

Swarm Intelligence Simulation Framework — PSO, ACO, Firefly, and Hybrid Algorithms

Python 3.11+ License: MIT Tests 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

Metadata

Release files for swarmlab 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for swarmlab 2.0.0
File Size Uploaded Provenance Actions
swarmlab-2.0.0.tar.gz 12.0 kB Without provenance Details for swarmlab-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for swarmlab 2.0.0
File Interpreter ABI Platform Actions
swarmlab-2.0.0-py3-none-any.whl Python 3 none any Details for swarmlab-2.0.0-py3-none-any.whl

Total release size: 25.4 kB

Release files / swarmlab-2.0.0.tar.gz

Download URL swarmlab-2.0.0.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
682408e50ff36b60475d19455927bdb573209c6437f18a60a94d4dc92392bcbc
BLAKE2b-256 checksum
How to use checksums
f504a627ddaa9e6083e2174f60c96517b081a63819e9702556d6515fff0dd225
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / swarmlab-2.0.0-py3-none-any.whl

Download URL swarmlab-2.0.0-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
685cff877844d87f9829e9f90d3b28fee99df868ecb77532d5dee237b90aea71
BLAKE2b-256 checksum
How to use checksums
ad0064dd899f8c49898551fa4b3bdd5336cd43b31e14e39b759576d42982cf3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for swarmlab 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page