Trying to create fitness function

77 Views Asked by At

enter image description here

I'm trying to create an idea fitness function using an inverse parabola but I'm struggling with the math.

Basically what I have is:

score = -1 * (actual-ideal)^2 + weight

Or 0 if the score is negative. This works great except that it's not flat enough, and it gives no score if the actual isn't close enough to the idea (at least not a positive value).

What I would ideally like is some kind of minimum score, so that f(0)=0, f(1)>0, etc. and anything above that in terms of x has some kind of value peaking at the ideal value.

Even better would be if I could have the score slowly decrease when the value goes past the ideal, but I'm ok with say 2*ideal being 0, so it's an inverse parabola. A more complex function would be awesome but right now I'm just looking for something simpler.

How would you adjust the equation above so that the score always starts at 0 and peaks out at the ideal?

1

There are 1 best solutions below

0
On

So you want to map the difference between actual and ideal to a score, where $f(0)$ is the max?

$f(x) = -(x-c)(x+c)$

Where $x$ is actual minus ideal and $c$ is just how big the difference needs to be to give $0$.

If you want a function directly of the actual:

$g(x) = -((x-I)-c)((x-I)+c)$

Where $I$ is the ideal

Put $g(0) = 0$ and see that $c$ can be $I$ or $-I$ (clearly doesn't matter which).

$g(x) = -x(x-2I)$

Is this what you're looking for?