【发布时间】:2019-11-25 15:02:49
【问题描述】:
我使用实验室中的仪器测量了以下数据。由于仪器根据其直径将不同尺寸的颗粒收集在箱中,因此测量基本上是“分箱”的:
import numpy as np
import matplotlib.pylab as plt
from lmfit import models
y = np.array([196, 486, 968, 2262, 3321, 4203, 15072, 46789, 95201, 303494, 421484, 327507, 138931, 27973])
bins = np.array([0.0150, 0.0306, 0.0548, 0.0944, 0.1540, 0.2560, 0.3830, 0.6050, 0.9510, 1.6400, 2.4800, 3.6700, 5.3800, 9.9100, 15])
bin_width=np.diff(bins)
x_plot = np.add(bins[:-1],np.divide(bin_width,2))
x=x_plot
y=y
这里绘制的是数据的外观。以 x-scale 为单位,有一个 0.1 左右的众数和一个 2 左右的众数。
在该研究领域内,通常将“多峰”对数正态分布拟合到此类数据:鉴于此,我使用 LMFIT 拟合了 2 左右的模式:
model = models.LognormalModel()
params = model.make_params(center=1.5, sigma=0.6, amplitude=2214337)
result = model.fit(y, params, x=x)
print(result.fit_report())
plt.plot(x, y, label='data')
plt.plot(x, result.best_fit, label='fit')
plt.xscale("log")
plt.yscale("log")
plt.legend()
plt.show()
正如预期的那样,这会很好地拟合 2 左右的第二种模式。我的问题是,我如何才能在 0.1 左右拟合第二种模式(基本上这两种模式的总和应该适合数据)?我意识到也可以说三种模式会更好,但我认为一旦我了解如何使用两种模式,添加第三种模式应该是微不足道的。
【问题讨论】:
标签: python curve-fitting lmfit