GeneticAlgorithmPython icon indicating copy to clipboard operation
GeneticAlgorithmPython copied to clipboard

Seed of Random Number Generators

Open dellannadavide opened this issue 4 years ago • 4 comments

Hi, first of all, thank you for the excellent work you do.

When experimenting for scientific research purposes, it is good practice to specify seeds for random number generators. This allows to support exact results replicability. I could not find the option to specify the seed of the random generators in the current library, for example when initializing the population.

I was wondering if I am missing something or if this is a potential enhancement of the current library.

Thank you.

dellannadavide avatar Oct 20 '21 17:10 dellannadavide

I am here for the same reason, Thank you

PierD86 avatar Dec 01 '21 15:12 PierD86

@ahmedfgad Is there a way to set a seed/random_state ?

ekerazha avatar Dec 08 '21 12:12 ekerazha

I found that we can fix the global random seed by setting two random seeds, numpy and python. (pygad codes use both of the random functions)

import numpy as np
import random

np.random.seed(x)
random.seed(x)

keechang-choi avatar Sep 02 '22 03:09 keechang-choi

@ekerazha @dellannadavide @keechang-choi @PierD86

This is supported in PyGAD 2.18.0. Thanks for your suggestions.

ahmedfgad avatar Sep 25 '22 17:09 ahmedfgad