我有一些测量数据,可以是一个很好的高斯分布,也可以是一个伽马分布,我目前有以下代码(代码片段),它对良好的高斯分布的数据执行得很好:
def gaussFunction(x, A, mu, sigma):
return A*numpy.exp(-(x-mu)**2/(2.*sigma**2))
# Snippet of the code that does the fitting
p0 = [numpy.max(y_points), x_points[numpy.argmax(y_points)],0.1]
# Attempt to fit a gaussian function to the calibrant space
try:
coeff, var_matrix = curve_fit(self.gaussFunction, x_points, y_points, p0)
newX = numpy.linspace(x_points[0],x_points[-1],1000)
newY = self.gaussFunction(newX, *coeff)
fig = plt.figure()
ax = fig.add_subplot(111)
plt.plot(x_points, y_points, 'b*')
plt.plot(newX,newY, '--')
plt.show()
证明它适用于高斯分布良好的数据点:
但问题是,我的一些数据点与良好的高斯分布不匹配,我得到:
我很想尝试使用cubic spline,但从概念上讲,我希望坚持高斯曲线拟合,因为这是数据中应该包含的数据结构(如第二个图所示,在某些数据中可能会出现拐点或尾部)。如果有人对如何处理这个“问题”有任何建议或建议,我将不胜感激。在
目前没有回答
相关问题 更多 >
编程相关推荐