Closed seallard closed 4 years ago
Here is one way to do it:
def stagnation_check(self):
for species in self.species:
if species.leader.original_fitness > self.champion_fitness:
self.champion_fitness = species.leader.original_fitness
self.epochs_since_improvement = 0
self.epochs_since_improvement += 1
if self.epochs_since_improvement > self.config.population_maximum_stagnation:
self.stagnation_reset()
def stagnation_reset(self):
"""Replace the population with offspring from the two best species. """
if len(self.species) > 1:
print("RESETTING POPULATION!")
self.species[0].expected_offspring = floor(self.config.population_size/2)
self.species[1].expected_offspring = floor(self.config.population_size/2)
for species in self.species[2:]:
species.expected_offspring = 0
self.champion_fitness = 0
self.epochs_since_improvement = 0
But the performance seems to get worse. Probably better to just rely on the speciation and mutations. Seems like a weird thing to do. Might be for "premature convergence prevention". https://en.wikipedia.org/wiki/Premature_convergence
If no fitness improvement has been observed in the entire population over a certain threshold, the original NEAT implementation replaces the entire population with offspring from the two best species.