【发布时间】:2021-08-23 22:08:02
【问题描述】:
我对 python 还很陌生,所以对我来说很陌生。我使用一些生成的数据绘制了直方图。这个数据有很多很多点。我已经用变量vals 定义了它。然后,我用这些值绘制了一个直方图,尽管我对其进行了限制,以便只考虑 104 到 155 之间的值。这样做如下:
bin_heights, bin_edges = np.histogram(vals, range=[104, 155], bins=30)
bin_centres = (bin_edges[:-1] + bin_edges[1:])/2.
plt.errorbar(bin_centres, bin_heights, np.sqrt(bin_heights), fmt=',', capsize=2)
plt.xlabel("$m_{\gamma\gamma} (GeV)$")
plt.ylabel("Number of entries")
plt.show()
我的下一步是考虑来自vals 的小于 120 的值。我这样做如下:
background_data=[j for j in vals if j <= 120] #to avoid taking the signal bump, upper limit of 120 MeV set
我需要在与直方图相同的图上绘制一条曲线,其形式为 B(x) = Ae^(-x/λ) 然后我使用最大似然估计公式估计了 λ 的值:
background_data=[j for j in vals if j <= 120] #to avoid taking the signal bump, upper limit of 120 MeV set
#print(background_data)
N_background=len(background_data)
print(N_background)
sigma_background_data=sum(background_data)
print(sigma_background_data)
lamb = (sigma_background_data)/(N_background) #maximum likelihood estimator for lambda
print('lambda estimate is', lamb)
其中羔羊 = λ。我得到的值大约是lamb = 27.75,我知道这是正确的。我现在需要估算一下 A。
有人建议我这样做:
Given a value of λ, find A by scaling the PDF to the data such that the area beneath
the scaled PDF has equal area to the data
我不太确定这意味着什么,或者我将如何尝试这样做。 PDF 表示概率密度函数。我假设必须进行集成,因此为了获得数据(vals)下的区域,我已经这样做了:
data_area= integrate.cumtrapz(background_data, x=None, dx=1.0)
print(data_area)
plt.plot(background_data, data_area)
但是,这给了我一个错误
ValueError: x and y must have same first dimension, but have shapes (981555,) and (981554,)
我不确定如何解决它。最终结果应该是这样的:
【问题讨论】:
标签: numpy matplotlib scipy estimation probability-distribution