简体   繁体   English

我可以在Python中使用scipy.stats之类的东西来创建适应度函数,就像分布

[英]Can I use something like scipy.stats, in Python, to create a fitness function responds like a distribution

I need to create a normalised fitness function for positive values 0→∞. 我需要为正值0→∞创建归一化的适应度函数。 I want to experiment, starting with (input→output) something like 0→0, 1→1, ∞→0. 我想尝试一下,从(输入→输出)类似0→0、1→1,∞→0的东西开始。 My maths is a bit weak and expect this is really not hard, if you no how. 我的数学有点薄弱,并且希望这真的不难,如果您不怎么做的话。

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. 因此,函数的输出应严重偏向0,我需要能够更改产生最大输出的输入值1。

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: 我可以制作一个线性函数,类似于三角形分布,但是然后我需要设置一个最大值,以区分输入(在该值之上,所有内容看起来都一样。)我还可以将两个简单的表达式与类似的东西合并在一起:

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 < 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()

弗兰肯函数输出

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. 仍然很丑陋,我希望可以灵活地使用scipy或类似的统计分布。

So you want a probability dustribution with a pdf of this form? 因此,您是否希望使用这种形式的pdf进行概率分配? Then you need to: 然后,您需要:

Alternatively, browse the list of distributions implemented in scipy.stats. 或者,浏览在scipy.stats中实现的发行版列表。 there are several with pdf shapes of this general form you're sketching. 您正在草绘这种通用形式的pdf形状。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM