From 6b0675b8c508d27e4a22017e62eee735c8b7af97 Mon Sep 17 00:00:00 2001 From: mohammed18salah Date: Sun, 12 Jul 2026 03:35:13 +0300 Subject: [PATCH] fix: ensure minimum sigma of 1.0 in Hill Climbing discrete iteration When epsilon is very small and the search grid is fine (e.g. np.arange(-10, 10, 0.01)), the noise sigma calculated as max_positions * epsilon can fall well below 0.5. Since discrete positions are represented as integer indices and noise is rounded, a sigma < 0.5 causes the noise to round to zero on almost every step, making the optimizer permanently stuck at its initial position. This fix enforces a minimum sigma of 1.0 (one index step), ensuring the optimizer always has a chance to move to an adjacent grid point, regardless of epsilon magnitude. Fixes #86 --- .../optimizers/local_opt/hill_climbing_optimizer.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/gradient_free_optimizers/optimizers/local_opt/hill_climbing_optimizer.py b/src/gradient_free_optimizers/optimizers/local_opt/hill_climbing_optimizer.py index f1e1354d..879c3a3f 100644 --- a/src/gradient_free_optimizers/optimizers/local_opt/hill_climbing_optimizer.py +++ b/src/gradient_free_optimizers/optimizers/local_opt/hill_climbing_optimizer.py @@ -191,8 +191,8 @@ def _iterate_discrete_batch(self) -> ndarray: max_positions = bounds[:, 1] sigmas = max_positions * self.epsilon - # Prevent zero sigma for single-value dimensions - sigmas = maximum(sigmas, 1e-10) + # Prevent getting stuck: ensure noise standard deviation is at least 1.0 index + sigmas = maximum(sigmas, 1.0) # Generate noise using the configured distribution noise_fn = self._DISTRIBUTIONS[self.distribution]