Closed smelfungus closed 3 years ago
Hi. Thanks for reporting. I will try to look into this over the weekend.
From an initial quick look, I would guess that you have a genome evaluator that may be assigning negative fitness scores(?) Probably I need better checks on such things. Do you have code that recreates the problem that I can look at? Either a repository or a zip maybe?
@colgreen exactly, I'm building a bridge between sharpneat and OpenAI Gym environments, and a negative fitness score (reward) is a typical case there. With the first version of sharpneat I was adding the base value to raw OpenAI Gym fitness but I thought this second version allows negative fitness (that would be great!).
I'll share my experiments soon, but nothing really tricky going there, FitnessInfo Evaluate(IBlackBox<double> box)
is communicating to the OpenAI Gym environment, getting total episode reward back, wrapping it in FitnessInfo
, and returning it.
I'm building a bridge between sharpneat and OpenAI Gym environments, and a negative fitness score (reward) is a typical case there.
This new version of SharpNEAT does still require non-negative fitness scores, so you will need to apply some function that maps the OpenAI Gym fitness scores to NEAT scores. Adding a baseline fitness can work if there is a known minimum, or if not then the following is perhaps a nicer general purpose solution:
y = e^(x-1)
or,
y = x < 1 ? e^(x-1) : x
i.e.
non_negative_fitness = fitness < 1 ? Math.Exp(fitness-1) : fitness;
See plots here:
https://www.desmos.com/calculator/2w2maf2ueo
That will work as a general purpose solution. It may be beneficial to refine that approach for individual OpenAI Gym tasks, but I I think that would be fine as a starting point.
I am going to add some checks in sharpneat to detect negative fitness scores, and to give a more useful error message when that happens.
While I'm here I want to thank you for your sponsorship/support over the last year! It is much appreciated! :)
@colgreen y = x < 1 ? e^(x-1) : x
is a great idea! It will allow both distinguishing between negative fitnesses and will provide almost linear positive part 👍🏻
I am glad to sponsor such a great project, that's the least I can do, thank you!
Closing, as this has been addressed by adding checks to the fitness scores; see 2406e75f6d1a39eeb299cdd486953697a3d42bbf
Thanks.
Hello, @colgreen! Thank you for that second sharpneat generation. Architecture, APIs, and ease of use are greatly enhanced! 🥇 I'm getting next frequent exceptions:
Pointing to this
NeatEvolutionAlgorithm
TrimSpeciesBackToElite
loop:Does it seem like
species.Stats.EliteSizeInt
may somehow become negative?