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

division by zero when pop size is 1 #214

Closed
JacobWoolbright opened this issue Jan 1, 2021 · 2 comments
Closed

division by zero when pop size is 1 #214

JacobWoolbright opened this issue Jan 1, 2021 · 2 comments

Comments

@JacobWoolbright
Copy link

File "C:\Users\hunty\AppData\Local\RLBotGUIX\venv\lib\site-packages\neat\math_util.py", line 9, in mean
    return sum(map(float, values)) / len(values)
ZeroDivisionError: division by zero

When the population size of my model is set to 1, I receive a division by 0 error, when set to a number > 1, I don't get the error. I found a stack overflow page relating to this, but there was no solution.

Here is some of my code:
config file (the portion that matters):

[NEAT]
fitness_criterion     = max
fitness_threshold     = 9999
pop_size              = 2
reset_on_extinction   = False

eval/fitness function:

def main(gnomes, config):
    global net, ge
    net = neat.nn.FeedForwardNetwork(gnomes[0], config)
    ge = gnomes[0]
    ge.fitness = 0

If you have a solution or need more code, please say so!

@ixenion
Copy link

ixenion commented Apr 1, 2021

yeah, same problem

@krzyLadda
Copy link

krzyLadda commented Nov 9, 2021

This is due to the lines:
gdmean = mean(distances.distances.values()) and
gdstdev = stdev(distances.distances.values())
in the species.py file.
But it is not big bug ;) The program wants to count the mean distance and mean deviation from a sequence of zero-length numbers. This is logical when there is only one genome, because to whom this genetic distance would be counted ;).
There are two solutions:
comment out this part in species.py.
gdmean = mean(distances.distances.values()) gdstdev = stdev(distances.distances.values()) self.reporters.info( 'Mean genetic distance {0:.3f}, standard deviation {1:.3f}'.format(gdmean, gdstdev))

OR
add an appropriate exception to mean and stdev in math_util.py. Somethink like:
'if not values:
return 0'

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

3 participants