DEAP / deap

Distributed Evolutionary Algorithms in Python
http://deap.readthedocs.org/
GNU Lesser General Public License v3.0
5.88k stars 1.13k forks source link

NSGA-III random seed inconsistency #624

Closed Leonidas-Z closed 2 years ago

Leonidas-Z commented 2 years ago

Hi everyone,

I am currently implementing a NSGA-III optimization framework. I wanted to reproduce the same solutions by specifying a seed (e.g. random.seed(1)). However, without success.

By looking at the generated data, I figured out that the random numbers were not reproducible in the selection operator, namely: selNSGA3. By investigating further, I found out that in the nitching function the numpy.random.shuffle(niche_individuals) is used instead of random.shuffle(niche_individuals).

Therefore, I had to change to random.shuffle(niche_individuals) to get reproducible results by using a specified seed. Another solution I found instead of changing the script was to just specify seed for both random.seed(1)) and numpy.random.seed(1).

Let me know if this is an issue or something that is done intentionally to improve the speed of the algorithm. Which of these two solutions do you think is better for my case?

Thank you!

fmder commented 2 years ago

Thanks for sharing! It is definitely half a bug I'd say. Your approach is a good one, if you look a CMA-ES (and its MO version) it also use numpy random. So I'd say, it should at least be mentioned in the documentation.

Leonidas-Z commented 2 years ago

Thank you so much for your response!