Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

neat.Population.run() does not return the best genome #271

Open
jongdetim opened this issue Jul 10, 2023 · 2 comments
Open

neat.Population.run() does not return the best genome #271

jongdetim opened this issue Jul 10, 2023 · 2 comments
Assignees

Comments

@jongdetim
Copy link

jongdetim commented Jul 10, 2023

Describe the bug
After training, the fittest genome is often not the one that was returned. Instead it seems to return the strongest genome from the final generation. I noticed that the top fitness during training can be higher than the genome returned by neat.Population.run().

To Reproduce
Steps to reproduce the behavior:

  1. Configure any model with a neat.StdOutReporter reporter
  2. Train the model, such as with:
    pe = neat.ParallelEvaluator(multiprocessing.cpu_count(), evaluate_genome)
    winner = population.run(pe.evaluate, 20)
  3. Observe the reported species MAX fitness genomes during training, and notice that the highest fitness if often not the one that population.run() returned.

Expected behavior
The genome returned by Population.run() should be the fittest genome it has seen at any point during training.

Stdout example

In the following output snippet, we can see that the max fitness of both species 2 and 3 is 22.0, however, the training function returns a genome with fitness: 17.0:

...
****** Running generation 18 ******

Population's average fitness: 2.98333 stdev: 4.80101
Best fitness: 22.00000 - size: (8, 19) - species 2 - id 956
Average adjusted fitness: 0.131
Mean genetic distance 2.401, standard deviation 0.954
Population of 59 members in 3 species:
ID age size fitness adj fit stag
==== === ==== ======= ======= ====
1 18 14 5.0 0.091 5
2 18 23 22.0 0.146 0
3 14 22 22.0 0.156 1
Total extinctions: 0
Generation time: 0.744 sec (0.499 average)

****** Running generation 19 ******

Population's average fitness: 2.79661 stdev: 3.76325
Best fitness: 17.00000 - size: (8, 19) - species 2 - id 956
Average adjusted fitness: 0.163
Mean genetic distance 2.369, standard deviation 1.078
Population of 61 members in 3 species:
ID age size fitness adj fit stag
==== === ==== ======= ======= ====
1 19 17 7.0 0.155 6
2 19 24 17.0 0.189 1
3 15 20 15.0 0.144 2
Total extinctions: 0
Generation time: 0.757 sec (0.531 average)
winner fitness: 17
Key: 956

Desktop (please complete the following information):

  • OS: Windows 10 64-bit
  • Python 3.9.6 64-bit
  • neat-python 0.92
@jongdetim
Copy link
Author

jongdetim commented Jul 10, 2023

I can also confirm the same happens when using a single process, instead of multiprocessing.
Strangely, looking through population.py, everything seems normal, as it returns self.best_genome.

My current workaround is instead calling population.reporters.reporters[0].best_genome() to get the best all-time genome.

@jongdetim jongdetim changed the title neat.Population.run() does NOT return the best genome neat.Population.run() does not return the best genome Jul 10, 2023
@CodeReclaimers
Copy link
Owner

Thank you for reporting this, especially the detailed reproduction! This code is long overdue for an overhaul after all the changes I've merged into it in the last couple years. I will try to find the time to get these issues addressed in a minor release soon, and leave the deep dive for later this year.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants