Skip to content

Commit d3dd987

Browse files
author
Oliver
committed
Fixed div by 0 error
1 parent 28789d3 commit d3dd987

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

pymoo/util/normalization.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def __init__(self, xl=None, xu=None) -> None:
6666
# now create all the masks that are necessary
6767
self.xl_only, self.xu_only = np.logical_and(~xl_nan, xu_nan), np.logical_and(xl_nan, ~xu_nan)
6868
self.both_nan = np.logical_and(np.isnan(xl), np.isnan(xu))
69-
self.neither_nan = ~self.both_nan
69+
self.neither_nan = np.logical_and(~np.isnan(xl), ~np.isnan(xu))
7070

7171
# if neither is nan than xu must be greater or equal than xl
7272
any_nan = np.logical_or(np.isnan(xl), np.isnan(xu))
@@ -76,18 +76,15 @@ def forward(self, X):
7676
if X is None or (self.xl is None and self.xu is None):
7777
return X
7878

79-
xl, xu, xl_only, xu_only = self.xl, self.xu, self.xl_only, self.xu_only
80-
both_nan, neither_nan = self.both_nan, self.neither_nan
81-
8279
# simple copy the input
8380
N = np.copy(X)
8481

8582
# normalize between zero and one if neither of them is nan
86-
N[..., neither_nan] = (X[..., neither_nan] - xl[neither_nan]) / (xu[neither_nan] - xl[neither_nan])
83+
N[..., self.neither_nan] = (X[..., self.neither_nan] - self.xl[self.neither_nan]) / (self.xu[self.neither_nan] - self.xl[self.neither_nan])
8784

88-
N[..., xl_only] = X[..., xl_only] - xl[xl_only]
85+
N[..., self.xl_only] = X[..., self.xl_only] - self.xl[self.xl_only]
8986

90-
N[..., xu_only] = 1.0 - (xu[xu_only] - X[..., xu_only])
87+
N[..., self.xu_only] = 1.0 - (self.xu[self.xu_only] - X[..., self.xu_only])
9188

9289
return N
9390

0 commit comments

Comments
 (0)