Skip to content

Commit

Permalink
Fixing division-by-zero errors in survival_score(..)
Browse files Browse the repository at this point in the history
  • Loading branch information
apanichella committed Aug 15, 2024
1 parent d7cc72b commit 36c7e5b
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions pymoo/algorithms/moo/age.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 36c7e5b

Please sign in to comment.