【发布时间】:2021-06-24 14:10:54
【问题描述】:
我目前正在为我的论文处理实验数据,并且遇到了 scipy curve_fit 的问题。
背景
这是一项关于 LED 发射的研究,使用以下模型描述特定 LED 成分/波长的吸收光谱。
型号是这样的:
基本思想是,我们得到了实验数据,我们想要拟合这个方程,以便我们对数据中的垂直偏移进行最佳猜测,这是实验中使用的设备的结果。为了获得垂直位移,curve_fit 中使用的函数将采用a + c * E * np.sqrt(E-bandE) * np.exp(-E*b) 的形式。 bandE/Eg 是指将在代码部分中提供的材料的带隙能量。 E是光子能量。
我做了什么
我在 pandas 数据框中使用的值作为列表供您复制和粘贴(如果需要),
photon_energy = [1.1271378805005456, 1.1169834851807208, 1.1070104183487501, 1.0972138659739825, 1.0875891829391229, 1.0781318856961741, 1.0688376453022415, 1.0597022808124787, 1.0507217530089832, 1.0418921584458825, 1.0332097237921667, 1.0246708004550413, 1.016271859467705, 1.0080094866265041, 0.9998803778633872, 0.9918813348404801, 0.9840092607544446, 0.9762611563390552, 0.9686341160551564, 0.9611253244578295, 0.9537320527312309, 0.9464516553821375, 0.939281567083788, 0.9322192996621053, 0.9252624392168658, 0.918408643370815, 0.9116556386401471, 0.9050012179201461, 0.898443238080145, 0.8919796176623023, 0.885608334679, 0.8793274245039717, 0.8731349778525352, 0.8670291388465735, 0.8610081031601389, 0.8550701162417932, 0.8492134716100002, 0.8434365092180953, 0.8377376138855407, 0.8321152137923491, 0.8265677790337335]
s2c = 1.0711371944297785, 1.0231329828975677, 1.0994106908895496, 1.5121380434280387, 1.4362625879245816, 1.6793735384201034, 1.967376254925342, 2.718958670464331, 2.8657461347457933, 3.2265806746948247, 4.073118384895329, 5.002080377098846, 5.518310980392261, 6.779117609004787, 7.923629188601875, 9.543272102194026, 11.061716095291905, 12.837722885549315, 15.156654004011116, 17.604461138085984, 20.853321055852934, 24.79640344112394, 28.59835938028905, 32.5257456, 37.87676923906976, 42.15321400245093, 46.794297771521705, 56.44267690099888, 61.60473904566305, 70.99822229568558, 77.60736232076566, 84.37513036736146, 92.9038746946938, 107.54475674330527, 117.91910226690293, 137.67481655050688, 158.02001455302846, 176.37334256204952, 195.20886164268876, 215.87011902349641, 240.41535423461914]
适合
bandE = 0.7435616030790153
def exp_fit(E, a, b, c):
# return a + c * E * np.sqrt(E - bandE) * np.exp(-E/0.046)# Eg and k are already defined previously
return a + c * E * np.sqrt(E-bandE) * np.exp(-E*b)
E = np.linspace(np.min(new_df['Photon Energy']), np.max(new_df['Photon Energy']),1000)
popt, pcov = curve_fit(exp_fit, new_df['Photon Energy'], new_df['S2c'],maxfev = 10000, p0=[0,500/23,1e+9]) # best guess of a,b, and c value
plt.plot(new_df['Photon Energy'], new_df['S2c'], 'o', label='S2c')
plt.plot(new_df['Photon Energy'], exp_fit(new_df['Photon Energy'], *popt), '-', label='S2c fit')
plt.ylabel('Emission Intensity (a.u.)')
plt.xlabel('Photon Energy (eV)')
plt.yscale('log')
plt.legend()
plt.show()
这就是我们最终得到的。
out: [1.59739310e+00 2.50268369e+01 9.55186101e+11]
所以在与我一起工作的人进行了长时间讨论之后(我们对 python 或数据科学并不了解),我们同意除了a 系数之外的所有内容都非常适合(b 并不重要,因为它将在稍后的步骤中明确计算。C 很重要,它似乎是正确的数量级)。因为它是垂直移动,我们预计a 是一个常数,但曲线因此而发散。
问题
正如问题标题和上一段中提到的,我们预计 a 大约是 5e-4 或在这个数量级范围内,但我们得到的东西对于这个实验来说太大了。如果有人精通 scipy 的 curve_fit 功能,请帮助我们!
附加信息,我们曾经使用名为 OriginLab(更昂贵的 microsoft excel)的东西,但它的许可证非常昂贵,所以我们正在尝试使用 python 代替。此方法在 OriginLab 上确实有效,并且不会导致拟合发散,因此我们认为它可能与 curve_fit 使用的算法有关。
【问题讨论】:
-
也许你可以试试
lmfitlmfit.github.io/lmfit-py 它也接受用户定义的模型lmfit.github.io/lmfit-py/…
标签: python scipy curve-fitting scipy-optimize