Platypus icon indicating copy to clipboard operation
Platypus copied to clipboard

seed option to keep the results reproducible

Open ashuein opened this issue 5 years ago • 3 comments

Is there a "seed" option in the Platypus which can be defined to keep the results reproducible?

ashuein avatar Feb 19 '20 14:02 ashuein

Try https://docs.python.org/3/library/random.html#random.seed

dhadka avatar Feb 19 '20 16:02 dhadka

Thanks dhadka for the response. The python random.seed function, I know, but I am asking how to use it in the Platypus function? NSGAII or NSGAIII doesn't seem to have a seed argument in the function call ?

ashuein avatar Feb 19 '20 17:02 ashuein

Hi @ashuein , you can try to monkey patch the initialization of the algorithm you are using to init a random seed. For example:

from platypus.algorithms import NSGAII 

old_init = NSGAII.__init__

def new_init(self, problem,
                 population_size = 100,
                 generator = RandomGenerator(),
                 selector = TournamentSelector(2),
                 variator = None,
                 archive = None,
                 seed = None
                 **kwargs):
    
    old_init(self, problem,
                 population_size = 100,
                 generator = RandomGenerator(),
                 selector = TournamentSelector(2),
                 variator = None,
                 archive = None,
                 **kwargs)
    
    if self.seed is None:
        self.seed = random.randint(0,1000)
        random.seed(self.seed)
    else:
        random.seed(self.seed)

NSGAII.__init__ = new_init

You can save that into a file and import before you begin calling Platypus stuff.

mronda avatar Feb 20 '20 21:02 mronda

This issue is stale and will be closed soon. If you feel this issue is still relevant, please comment to keep it active. Please also consider working on a fix and submitting a PR.

github-actions[bot] avatar Nov 04 '22 20:11 github-actions[bot]