【发布时间】:2021-07-22 08:44:55
【问题描述】:
我正在尝试拟合二分量高斯拟合:
mu0 = sum(velo_peak * spec_peak) / sum(spec_peak)
sigma = np.sqrt(sum(spec_peak * (velo_peak - mu0)**2) / sum(spec_peak))
def Gauss(velo_peak, a, mu0, sigma):
res = a * np.exp(-(velo_peak - mu0)**2 / (2 * sigma**2))
return res
p0 = [max(spec_peak) - RMS, mu0, sigma] # a = max(spec_peak)
popt,pcov = curve_fit(Gauss, velo_peak, spec_peak, p0,maxfev=10000, bounds=((0, 0, +np.inf, +np.inf), (0, 0, +np.inf, +np.inf)))
#____________________two component gaussian fit_______________________#
def double_gaussian(velo_peak,a1, mu1, sigma1, a2, mu2, sigma2):
res_two = a1 * np.exp(-(velo_peak - mu1)**2/(2 * sigma1**2)) \
+ a2 * np.exp(-(velo_peak - mu2)**2/(2 * sigma2**2))
return res_two
##_____________________Initial guess values__________________________##
sigma1 = 0.7 * sigma
sigma2 = 0.7 * sigma
mu1 = mu0 + sigma
mu2 = mu0 - sigma
a1 = 3
a2 = 1
guess = [a1, mu1, sigma1, a2, mu2, sigma2]
popt_2,pcov_2 = curve_fit(double_gaussian, velo_peak, spec_peak, guess,maxfev=10000, bounds=((0, 0, +np.inf, +np.inf), (0, 0, +np.inf, +np.inf)))
但是我得到了一个我想避免的负面部分,但我不知道如何正确实现边界,因为我不太了解文档。
我收到以下错误:
ValueError: Inconsistent shapes between bounds and `x0`.
谁能指导我如何正确使用边界?
【问题讨论】:
-
这能回答你的问题吗? UIView frame, bounds and center
标签: python numpy scipy curve-fitting bounds