Can I use something like scipy.stats, in Python, to create a fitness function responds like a distribution
<p>I need to create a normalised fitness function for positive values 0ââ. I want to experiment, starting with (inputâoutput) something like 0â0, 1â1, ââ0. My maths is a bit weak and expect this is really not hard, if you no how.</p>

<p>So the output of the function should be heavily skewed towards 0 and I need to be able to change the input value which produces the maximum output, 1.</p>

<p>I could make a linear function, something like a triangular distribution, but then I need to set a maximum value at which input would be distinguished (above that value everything looks the same.) I could also merge two simple expressions together with something like this:</p>

<pre><code>from matplotlib import pyplot as plt
import numpy as np
from math import exp

def frankenfunc(x, mu):

    longtail = lambda x, mu: 1 / exp((x - mu))
    shortail = lambda x, mu: pow(x / mu, 2)
    if x &lt; mu:
        return shortail(x, mu)
    else:
        return longtail(x, mu)

x = np.linspace(0, 10, 300)
y = [frankenfunc(i, 1) for i in x]
plt.plot(x, y)
plt.show()
</code></pre>

<p><a href="http://i.stack.imgur.com/PqoPa.png" rel="nofollow"><img src="http://i.stack.imgur.com/PqoPa.png" alt="Franken function output"></a></p>

<p>This is ok and should work, especially as the actual values it returns don't matter too much as they will be used in a binary tournament. Still it's ugly and I'd like the flexibility to use the statistical distributions from scipy or something similar if possible.</p>

<p>So you want a probability dustribution with a pdf of this form? Then you need to:</p>

<ul>
<li>normalize it (the integral of pdf over the domain is unity)</li>
<li>subclass the rv_continuous class like shown in the docs, <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html" rel="nofollow">http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_continuous.html</a>, with your function for the _pdf method.</li>
</ul>

<p>Alternatively, browse the list of distributions implemented in scipy.stats. there are several with pdf shapes of this general form you're sketching.</p>

python scipy fitness