我想在 1-100 之间随机选择一个数字,这样获得数字 60-100 的概率高于 1-59。
我希望数字 1-100 的概率为左偏分布。也就是说,它有一个长尾和一个峰。
大致意思是:
pers = np.arange(1,101,1)
prob = <left-skewed distribution>
number = np.random.choice(pers, 1, p=prob)
我不知道如何生成左偏离散概率函数。有任何想法吗?谢谢!
这就是您使用 SciPy 函数“skewnorm”寻找的答案。它可以使任何正整数集向左或向右倾斜。
from scipy.stats import skewnorm
import matplotlib.pyplot as plt
numValues = 10000
maxValue = 100
skewness = -5 #Negative values are left skewed, positive values are right skewed.
random = skewnorm.rvs(a = skewness,loc=maxValue, size=numValues) #Skewnorm function
random = random - min(random) #Shift the set so the minimum value is equal to zero.
random = random / max(random) #Standadize all the vlues between 0 and 1.
random = random * maxValue #Multiply the standardized values by the maximum value.
#Plot histogram to check skewness
plt.hist(random,30,density=True, color = 'red', alpha=0.1)
plt.show()
请参考此处的文档:https://docs.scipy.org/doc/scipy/reference/ generated/scipy.stats.skewnorm.html https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.skewnorm.html
左偏分布的直方图 https://i.stack.imgur.com/XXcb8.png
该代码生成以下图。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)