Skip to content

Commit

Permalink
Fix compatibility with numpy 2.0 and allow use of last version of cma (
Browse files Browse the repository at this point in the history
…#639)

* Fix: use math instead of numpy.math module

* Fix: use np.prod instead of np.product

* Allow use of cma>=3.2.2 to allow for numpy 2.0 compatibility
  • Loading branch information
iglasser authored Aug 25, 2024
1 parent 9d851f4 commit e00e3c1
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pymoo/algorithms/soo/nonconvex/es.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import math

from pymoo.algorithms.base.genetic import GeneticAlgorithm
from pymoo.algorithms.soo.nonconvex.ga import FitnessSurvival
Expand Down Expand Up @@ -43,9 +44,9 @@ def __init__(self,
"""

if pop_size is None and n_offsprings is not None:
pop_size = int(np.math.ceil(n_offsprings * rule))
pop_size = int(math.ceil(n_offsprings * rule))
elif n_offsprings is None and pop_size is not None:
n_offsprings = int(np.math.floor(pop_size / rule))
n_offsprings = int(math.floor(pop_size / rule))

assert pop_size is not None and n_offsprings is not None, "You have to at least provivde pop_size of n_offsprings."
assert n_offsprings >= 2 * pop_size, "The number of offsprings should be at least double the population size."
Expand Down
4 changes: 2 additions & 2 deletions pymoo/util/mnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def calc_mnn_base(X, n_remove=0, twonn=False):

D = squareform(pdist(X, metric="sqeuclidean"))
Dnn = np.partition(D, range(1, M+1), axis=1)[:, 1:M+1]
d = np.product(Dnn, axis=1)
d = np.prod(Dnn, axis=1)
d[extremes] = np.inf

n_removed = 0
Expand All @@ -63,7 +63,7 @@ def calc_mnn_base(X, n_remove=0, twonn=False):

D[:, k] = np.inf
Dnn[H] = np.partition(D[H], range(1, M+1), axis=1)[:, 1:M+1]
d[H] = np.product(Dnn[H], axis=1)
d[H] = np.prod(Dnn[H], axis=1)
d[extremes] = np.inf

return d
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
'scipy>=1.1',
'matplotlib>=3',
'autograd>=1.4',
'cma==3.2.2',
'cma>=3.2.2',
'alive-progress',
'dill',
'Deprecated'],
Expand Down

0 comments on commit e00e3c1

Please sign in to comment.