如何比较随机数的概率分布函数

2024-04-29 02:40:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我想比较一下numpy.random提供的概率distributions。理想情况下,我希望看到一组图表比较它们,但我对其他想法持开放态度。在

我可以想象使用matplotlib遍历每个函数并进行绘图。也许以前有人做过?在


Tags: 函数numpy绘图matplotlib图表情况random概率
1条回答
网友
1楼 · 发布于 2024-04-29 02:40:31

我不确定所有的功能都可以直接比较。但是,我可以比较的功能如下所示: numpy.random pdfs

代码:

    loc, scale = 0., 1
    x=np.arange(-8., 8., .01)
    laplace = np.exp(-abs(x-loc/scale))/(2.*scale)
    gumbel = (1/scale)*np.exp(-(x - scale)/scale)* np.exp( -np.exp( -(x - scale) /scale) )
    logistic = np.exp((loc-x)/scale)/(scale*(1+np.exp((loc-x)/scale))**2)
    normal = 1/(scale * np.sqrt(2 * np.pi))*np.exp( - (x - loc)**2 / (2 * scale**2) )
    lognormal = (np.exp(-(np.log(x) - loc)**2 / (2 * scale**2))/ (x * scale * np.sqrt(2 * np.pi)))
    rayleigh = (x/(scale*scale))*(np.exp((-x*x)/(2*scale*scale)))
    standard_cauchy = 1/(np.pi*(1+(x*x)))


    plt.plot(x,gumbel,label='gumbel scale=1')
    plt.plot(x,laplace,label='laplace scale=1, loc = 0')
    plt.plot(x,normal,label='normal scale=1, loc = 0')
    plt.plot(x,logistic,label='logistic scale=1, loc = 0')
    plt.plot(x,lognormal,label='lognormal scale=1, loc = 0')
    plt.plot(x,rayleigh,label='rayleigh scale=1')
    plt.plot(x,standard_cauchy,label='standard_cauchy')

相关问题 更多 >