CodeReclaimers / neat-python

Python implementation of the NEAT neuroevolution algorithm
BSD 3-Clause "New" or "Revised" License
1.42k stars 493 forks source link

Update fitness_threshold from a checkpoint #229

Open keenhon opened 2 years ago

keenhon commented 2 years ago

Hi,

I would like to know if there is a way to change the fitness_threshold for a saved checkpoint?

Thanks

luke-saunders commented 2 years ago

Hello -- a few months ago, I needed to adjust some config values on a checkpoint. I made the following change in 'checkpoint.py'. It allows to substitute an updated config when restoring a checkpoint.

NOTE: I'm unsure if this causes adverse conditions for the algorithm. It's handy to be able to make changes mid-evolution, so I'd be grateful if anyone could provide insights, and improvements if required.

def restore_checkpoint(filename, update_config=None):
        """Resumes the simulation from a previous saved point"""
        with gzip.open(filename) as f:
            generation, config, population, species_set, rndstate = pickle.load(f)
            random.setstate(rndstate)            
            if update_config==None:
                return Population(config, (population, species_set, generation))
            else:
                return Population(update_config, (population, species_set, generation))