anyoptimization / pymoo

NSGA2, NSGA3, R-NSGA3, MOEAD, Genetic Algorithms (GA), Differential Evolution (DE), CMAES, PSO
https://pymoo.org
Apache License 2.0
2.28k stars 390 forks source link

mtrand.pyx error #470

Closed pamdla closed 11 months ago

pamdla commented 1 year ago

import numpy as np

from pymoo.algorithms.moo.nsga3 import NSGA3
from pymoo.factory import get_problem, get_reference_directions
from pymoo.optimize import minimize
from pymoo.problems.multi import TNK
from pymoo.visualization.scatter import Scatter
from pysamoo.algorithms.gpsaf import GPSAF

problem = TNK()

ref_dirs = get_reference_directions("das-dennis", 2, n_points=20)

# create the algorithm object

## 1
algorithm = NSGA3(pop_size=20,
                  n_offsprings=10,
                  ref_dirs=ref_dirs)

## 2
algorithm = GPSAF(algorithm,
                  alpha=10,
                  beta=50,
                  n_max_doe=100,
                  )

## 3
res = minimize(
    problem,
    algorithm,
    ('n_evals', 200),
    seed=1,
    verbose=True)

The full example codes are above.

When I test ##1 with ##3 there is no error, but if continuing using ##2 after ##1, then ##3 will prompt error like this:

File "mtrand.pyx", line 950, in numpy.random.mtrand.RandomState.choice
ValueError: 'a' cannot be empty unless no samples are taken

The install numpy is 1.25.1, then I reinstall numpy to 1.20.0, still the error is there.

any suggestion?

blankjul commented 1 year ago

what pymoo version are you using? Does the error also occur with only NSGA2?

blankjul commented 11 months ago

Feel free to repost in the pysamoo framework as this is related to GPSAF.