From 36c7e5baec125a0a4120bd1c199f9bdaa4278b93 Mon Sep 17 00:00:00 2001 From: apanichella Date: Thu, 15 Aug 2024 10:44:22 +0200 Subject: [PATCH] Fixing division-by-zero errors in survival_score(..) --- pymoo/algorithms/moo/age.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/pymoo/algorithms/moo/age.py b/pymoo/algorithms/moo/age.py index 582468e3..5a2776f6 100644 --- a/pymoo/algorithms/moo/age.py +++ b/pymoo/algorithms/moo/age.py @@ -167,7 +167,13 @@ def survival_score(self, front, ideal_point): p = self.compute_geometry(front, extreme, n) nn = np.linalg.norm(front, p, axis=1) - distances = self.pairwise_distances(front, p) / (nn[:, None]) + # Replace very small norms with 1 to prevent division by zero + nn[nn < 1e-8] = 1 + + distances = self.pairwise_distances(front, p) + distances[distances < 1e-8] = 1e-8 # Replace very small entries to prevent division by zero + + distances = distances / (nn[:, None]) neighbors = 2 remaining = np.arange(m) @@ -209,7 +215,7 @@ def compute_geometry(front, extreme, n): return p @staticmethod - @jit(nopython=True, fastmath=True) + #@jit(nopython=True, fastmath=True) def pairwise_distances(front, p): m = np.shape(front)[0] distances = np.zeros((m, m))