From 9a00aa09848d96399980e52d2487295a1b853dd7 Mon Sep 17 00:00:00 2001 From: stijn Date: Mon, 23 Jun 2025 11:19:32 +0200 Subject: [PATCH] Change Firefly algorithm to use negation instead of division Currently, Firefly computes particle intensity as `1 / score`, so a lower score gives a higher intensity. While this works for positive scores, it fails when scores can be negative. This commit switches the calculation to `-score`, which keeps the "higher intensity is better" behavior, but handles negative scores correctly. --- kernel_tuner/strategies/firefly_algorithm.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/kernel_tuner/strategies/firefly_algorithm.py b/kernel_tuner/strategies/firefly_algorithm.py index dc43aae6f..259a94f5c 100644 --- a/kernel_tuner/strategies/firefly_algorithm.py +++ b/kernel_tuner/strategies/firefly_algorithm.py @@ -94,7 +94,7 @@ def __init__(self, bounds): """Create Firefly at random position within bounds.""" super().__init__(bounds) self.bounds = bounds - self.intensity = 1 / self.score + self.intensity = -self.score def distance_to(self, other): """Return Euclidian distance between self and other Firefly.""" @@ -103,10 +103,7 @@ def distance_to(self, other): def compute_intensity(self, fun): """Evaluate cost function and compute intensity at this position.""" self.evaluate(fun) - if self.score == sys.float_info.max: - self.intensity = -sys.float_info.max - else: - self.intensity = 1 / self.score + self.intensity = -self.score def move_towards(self, other, beta, alpha): """Move firefly towards another given beta and alpha values."""