Firefly Algorithm (Yang 2008) is a population-based metaheuristic where fireflies are attracted to brighter (lower-objective) fireflies. The movement of firefly i toward a brighter firefly j is xi += β·(xj − xi) + α·ε, with attractiveness β = β0·exp(−γ·r2) and a small random jitter α·ε. HumpDay's
FireflyAlgorithm follows Yang's recipe and adds the two ingredients that make it competitive on the SOTA benchmark:
- Geometric damping of the randomness coefficient: α ← 0.99·α at the end of each sweep. Without damping, the random jitter prevents convergence onto the optimum — this was the snapshot's Ackley failure mode before the fix.
- L-BFGS-B polish from the firefly best at the end.
HumpDay's Firefly at a glance
- Population:
n_fireflies = min(15, max(2, budget // 5)). - Attractiveness: β0 = 1, γ = 1.
- Randomness: α0 = 0.2 with geometric damping 0.99 per sweep (matches mealpy's
alpha_damp). - Polish: reserve
min(20·n_dim, n_trials/2)evaluations for L-BFGS-B from the best firefly.
Interactive 3D Visualization
See Firefly Algorithm in action on 3D optimization surfaces:
Loading 3D visualization...
Requires WebGL support
Instructions: Choose a test function and algorithm, then click Start to watch the step-by-step optimization process.
Implementation Details
| Component | Details | Links |
|---|---|---|
| Original Algorithm |
Xin-She Yang Bio-inspired optimization algorithm Based on flashing patterns and behavior of fireflies Published: 2008 |
Original Paper |
| Reference Implementation |
mealpy FFA Tested against mealpy's Original Firefly Algorithm. Reference: mealpy.swarm_based.FFA.OriginalFFA
|
mealpy |
| HumpDay Python |
HumpDay FireflyAlgorithmYang-standard Firefly with α damping, then L-BFGS-B polish from the best firefly. Pure Python; no required dependencies. File: humpday/optimizers/evolutionary_algorithms.py
|
Source |
| Humpday JavaScript |
Browser Implementation Pure JavaScript firefly algorithm Light intensity, attractiveness, and movement modeling Class: FireflyAlgorithm |
JS Implementation |
Performance Characteristics
- Best for: Multimodal continuous objectives. The swarm covers basins, α damping focuses the search late, and the L-BFGS-B polish refines the winner.
- Worst for: Tight-budget problems where the pairwise O(n_fireflies2) attractor updates dominate.
- Per sweep: up to n_fireflies2 attractive moves and evaluations; α damps by factor 0.99 at end of sweep.
- Relative to mealpy FFA at
n_trials=200, n_dim=2: HumpDay wins across sphere, Rosenbrock, and Ackley. See SOTA status for the live numbers.
Educational Resources
- Firefly Algorithm Wikipedia
- Original Firefly Algorithm Paper (Yang, 2008)
- Nature-Inspired Metaheuristic Algorithms
- FA for Multimodal Optimization
- GitHub Firefly Algorithm Implementations
Algorithm Components
- Light Intensity: I(r) = I₀ × e^(-γr²) where r is distance
- Attractiveness: β(r) = β₀ × e^(-γr²) where β₀ is attractiveness at r=0
- Movement Rule: x_i = x_i + β(r_ij)(x_j - x_i) + α(rand - 0.5)
- Randomization: α controls random walk component
- Light Absorption: γ controls light absorption coefficient
Mathematical Foundation
- Objective Function: f(x) directly relates to light intensity I ∝ f(x)
- Distance Metric: Typically Euclidean: r_ij = ||x_i - x_j||
- Movement Equation: x_i^(t+1) = x_i^t + β₀e^(-γr²)(x_j^t - x_i^t) + αε_i^t
- Parameter Ranges: α ∈ [0,1], β₀ ∈ [0,1], γ ∈ [0,∞)
️ Key Parameters
- Population Size: Typically 20-50 fireflies
- α (Randomization): Usually 0.2-0.5, decreases over time
- β₀ (Attractiveness): Usually 1.0 (maximum attractiveness)
- γ (Absorption): Usually 0.01-10, controls exploitation vs exploration
- Generations: Stopping criteria based on evaluations or convergence
Firefly Algorithm Pseudocode
function fireflyAlgorithm(problem, n_fireflies, max_generations):
// Initialize firefly population randomly
fireflies = initializePopulation(n_fireflies)
for generation in 1 to max_generations:
for each firefly i:
for each firefly j:
if light_intensity(j) > light_intensity(i):
r = distance(i, j)
attractiveness = β₀ * exp(-γ * r²)
move firefly i towards j with attractiveness
add random component α * (rand - 0.5)
evaluate new position and update light intensity
return best firefly
Firefly Algorithm Variants
- Standard FA: Original Yang formulation
- Discrete FA: Adapted for combinatorial problems
- Multi-Objective FA: MOFA for Pareto optimization
- Chaotic FA: Chaotic maps for parameter control
- Hybrid FA: Combined with local search or other methods
- Adaptive FA: Self-adjusting parameters during search
Applications
- Engineering Design: Structural optimization, antenna design
- Image Processing: Feature selection, clustering
- Neural Networks: Training weights and architecture
- Scheduling: Task scheduling and resource allocation
- Data Mining: Classification and clustering problems
- Economics: Portfolio optimization and forecasting
Advantages of Firefly Algorithm
- Automatic Subdivision: Swarm can naturally divide into subgroups
- Multimodal Capability: Can find multiple optima simultaneously
- Parameter Flexibility: Few parameters to tune
- Local Attraction: Fireflies mainly interact with nearby neighbors
- Global Communication: Brightest firefly influences entire swarm
️ Limitations
- Parameter Sensitivity: Performance depends on α, β₀, γ settings
- Convergence Speed: May be slower than specialized algorithms
- High Dimensions: Performance degrades in very high dimensions
- Computational Cost: O(n²) interactions per generation
- Premature Convergence: May converge too quickly with wrong parameters