ahmedfgad / GeneticAlgorithmPython

Source code of PyGAD, a Python 3 library for building the genetic algorithm and training machine learning algorithms (Keras & PyTorch).
https://pygad.readthedocs.io
BSD 3-Clause "New" or "Revised" License
1.87k stars 462 forks source link

Seed of Random Number Generators #70

Open dellannadavide opened 3 years ago

dellannadavide commented 3 years ago

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.

PierD86 commented 2 years ago

I am here for the same reason, Thank you

ekerazha commented 2 years ago

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

keechang-choi commented 2 years ago

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)
ahmedfgad commented 2 years ago

@ekerazha @dellannadavide @keechang-choi @PierD86

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