我过去曾使用 random.normal() 来生成一个数字,如果多次调用该数字,总计将创建一个钟形曲线分布。我现在想做的是创建相反/逆的分布,其中分布偏向某个范围内的极端? excel中有一些内置函数似乎可以满足我的要求。有没有办法在 python 中做到这一点?谢谢
看来您想要一个具有“颠倒钟形曲线”的分布
与正态分布相比。如果是的话,那么下面的方法
通过拒绝采样和修改后的
标准正态分布的版本。 'x0' 和 'x1' 是范围
要生成的数字。
def invertedNormal(x0, x1):
# Get the ends of the PDF (the bounding
# box will cover the PDF at the given range)
x0pdf = 1-math.exp(-(x0*x0))
x1pdf = 1-math.exp(-(x1*x1))
ymax = max(x0pdf, x1pdf)
while True:
# Choose a random x-coordinate
x=random.random()*(x1-x0)+x0
# Choose a random y-coordinate
y=random.random()*ymax
# Return x if y falls within PDF
if y < 1-math.exp(-(x*x)):
return x
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)