CodeReclaimers / neat-python

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

Wrong number of genomes in population. #270

Open bable631 opened 1 year ago

bable631 commented 1 year ago

Describe the bug I set the number of genomes per generation to 250, but 546 were created on the FIRST generation.

To Reproduce Steps to reproduce the behavior:

  1. Create population with 250 genomes (set in config)
  2. Population has many more genomes than you specified in config.

Expected behavior There should be exactly 250 genomes. No more, no less.

Desktop (please complete the following information):

Additional context I am running this in python 3.10 I started using this version of NEAT-Python because the regular version that you can install with pip had a similar but different bug that I was trying to avoid. Honestly, this bug seems even worse. That said, if I can't use this code or the other version than I will need to completely redo all of my code with a different neural network algorithm and that's months of work wasted.

SquarishRectangle commented 1 year ago

I came here to complain about this as well, but this seems to be more of a side effect and not a bug. If your compatibility_threshold is set too low, it will assume each genome in your starting population is an individual species, thus having 250 species in total. By default, each species must have a minimum of 2 members after reproduction, which results in about double the specified population size. This should go away after 15 generations (or whatever you set your max_stagnation to). Generally, I find that this actually results in better evolution since the population is more diverse, but at the same time, the same diversity can be achieved if we simply cut the number of species in half.

There are easy ways to fix this such as increasing your compatibility_threshold or reducing min_species_size among other settings you can tweak, but this behavior really shouldn't be here in the first place.

bable631 commented 1 year ago

I actually did discover this solution before you said it, but I didn't update my comment lol.

On Sun, Jul 2, 2023, 6:33 PM YuXiang Hao @.***> wrote:

I came here to complain about this as well, but this seems to be more of a side effect and not a bug. If your compatibility_threshold is set too low, it will assume each genome in your starting population is an individual species, thus having 250 species in total. By default, each species must have a minimum of 2 members after reproduction, which results in about double the specified population size. This should go away after 15 generations (or whatever you set your max_stagnation to). Generally, I find that this actually results in better evolution since the population is more diverse, but at the same time, the same diversity can be achieved if we simply cut the number of species in half.

There are easy ways to fix this such as increasing your compatibility_threshold or reducing min_species_size among other settings you can tweak, but this behavior really shouldn't be here in the first place.

— Reply to this email directly, view it on GitHub https://github.com/CodeReclaimers/neat-python/issues/270#issuecomment-1616884524, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADE5WPE2HPTFOLDUWZ2HV63XOHZNBANCNFSM6AAAAAAZ2PONZU . You are receiving this because you authored the thread.Message ID: @.***>

bable631 commented 11 months ago

I'm now having a similar issue that is not being solved by modifying the config: the population is decreasing every generation. I start at 300 population and decrease by about 6 per generation on average. Very weird.