我包括下面编写的代码。由于某种原因,与初始分布相比,上限为0.804。我正在使用的两个发行版都会发生这种情况。

这是rv_continuous的常见问题,还是我错过了什么?

import matplotlib.pyplot as plt
import scipy.stats as st

class Disk_pdf(st.rv_continuous):
    def _pdf(self,x):
        return (x*(1-np.exp((x-0.804)/0.2539)))/((1+x)*(x**2+0.0256**2)**0.5)

Disk_cv = Disk_pdf(a=0,b=0.804,name='Disk_pdf')
Disk_dist = Disk_cv.rvs(size = 10000)
plt.figure()
plt.hist(Disk_dist,100)




class Bulge_pdf(st.rv_continuous):
    def _pdf(self,x):
        return x*np.exp(-2.368*x-6.691*x**2)
Bulge_cv = Bulge_pdf(a=0,b=0.804,name='Bulge_pdf')

Bulge_dist = Bulge_cv.rvs(size = 10000)
plt.figure()
plt.hist(Bulge_dist,100)


初始分布图和使用rv_continuous创建的直方图如下。我有两张直方图图像,其中一张放大显示该分布是通过除超出采样上限的方法捕获的。另一幅图像以y比例显示直方图,该直方图显示了过采样问题的严重程度。

Initial Disk galaxies' distribution and histograms made using rv_continuous which have over sampled upper bound.

Initial Bulge dominated galaxies' distribution and histograms made using rv_continuous which have over sampled upper bound.

最佳答案

pdf必须规范化,而您的pdf似乎不是:

In [6]: from scipy.integrate import quad

In [7]: quad(Disk_cv.pdf, 0, 0.804)
Out[7]: (0.41121809643549406, 4.005573481922018e-09)

关于python - 为什么scipy.stats.rv_continuous选择上限太多次了?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35865143/

10-10 11:10