【发布时间】:2021-03-06 21:30:53
【问题描述】:
我正在尝试将广义极值 (GEV) 分布的概率密度函数 (pdf) 与数据的 pdf 匹配。该直方图是 bin 的函数。当调整这个 bin 时,函数拟合的结果也会发生变化。而curve_fit(func, x, y) 正在正确地扮演这个角色。但是这个函数使用“最小二乘估计”。我想要的是使用最大似然估计(MLE)。使用stats.genextreme.fit(data)function 效果很好。但是,此函数不表示根据 bin 的直方图形状变化。只需使用原始数据即可。
我正在尝试使用 MLE。我成功地使用 MLE 估计了标准正态分布的参数。但是,它是基于原始数据的,不会根据 bin 而变化。甚至GEV的参数也无法用原始数据进行估计。
我查了genextreme_gen、rv_continuous等的源代码,但是这个代码太复杂了。以我的 Python 技能无法接受源代码。
我想通过 MLE 估计 GEV 分布的参数。我想得到估计根据 bin 变化的结果。
我该怎么办?
对不起,我的英语很差,感谢您的帮助。
+)
h = 0.5 # bin width
dat = h105[1] # data
b = np.arange(min(dat)-h/2, max(dat), h) # bin range
n, bins = np.histogram(dat, bins=b, density=True) # histogram
x = 0.5*(bins[1:]+bins[:-1]) # x-value of histogram
popt,_ = curve_fit(fg, x, n) # curve_fit(GEV's pdf, x-value of histogram, pdf value)
popt = -popt[0], popt[1], popt[2] # estimated paramter (Least squares estimation, LSE)
x1 = np.linspace((popt[1]-popt[2])/popt[0], dat.max(), 1000)
a1 = stats.genextreme.pdf(x1, *popt) # pdf
popt = stats.genextreme.fit(dat) # estimated parameter (Maximum likelihood estimation, MLE)
x2 = np.linspace((popt[1]-popt[2])/popt[0], dat.max(), 1000)
a2 = stats.genextreme.pdf(x2, *popt)
bin 宽度 = 2
bin 宽度 = 0.5
【问题讨论】:
-
您能否澄清一下,您所说的估计参数是基于原始数据并且不会根据 bin 更改是什么意思?您估计参数的代码也会很有用。请提供具体示例以及您获得的结果和您期望的结果。
标签: python data-fitting probability-density mle