使用scipy.optimize.curve_fit()获取参数的协变性似乎是一个常见的问题,但是通用的解决方案对我并没有多大帮助。(没有给出一个很好的初始猜测,没有足够的数据点,没有输入一个numpy数组,也没有使用float64)。这重复了我的错误:
x = np.array([103.15, 113.15, 269.3, 273.15, 273.15, 283.15, 290.0, 293.15, 293.15, 296.15, 296.15, 303.15, 303.15, 303.15, 310.0, 313.15, 313.15, 318.15, 323.15, 323.15, 330.0, 333.15, 348.16, 350.0, 353.15])
y = np.array([-0.2468283, -0.19681169, -0.01856526, -0.01707074, -0.01698771, -0.01333444, -0.01072733, -0.00986383, -0.00974759, -0.00830289, -0.00896712, -0.00699103, -0.00667552, -0.0063102, -0.00440053, -0.00368648, -0.0034374, -0.00199269, -0.00092992, -0.00066423, 0.00106277, 0.00166058, 0.00464962, 0.0060445,0.00650947])
((u0, u1, r0, r1), pcov) = scipy.optimize.curve_fit(f, x, y, p0=np.array([1.0, 0.01, 0.3, 0.5]))
print(u0, u1, r0, r1)
print(pcov)
我的职责是:
def f(x, u0, u1, r0, r1):
k = 8.617333262145E-5
term1 = (np.exp(-u0/(k*x)) - np.exp(u1/(k*x))) * r0**3
term2 = (np.exp(u1/(k*x)) - 1) * r1**3
return -(2 * np.pi / 3) * (term1 + term2)
输出是
OptimizeWarning: Covariance of the parameters could not be estimated
warnings.warn('Covariance of the parameters could not be estimated',
1.0 0.010062693926842859 0.3093891634616651 0.4627801922742623
[[inf inf inf inf]
[inf inf inf inf]
[inf inf inf inf]
[inf inf inf inf]]
用最合适的方法绘制数据点,显示出很好的匹配。我真的不知道用协方差来解释这个问题。有什么想法吗?
发布于 2020-11-05 00:29:39
根据文档
如果解处的雅可比矩阵没有满秩,则lm方法返回一个充满np.inf的矩阵,而‘trf’和‘dogbox’方法则使用Moore-Penrose伪逆方法计算协方差矩阵。
我试着在你的数据上使用method='trf'
,看起来很有效。我不知道为什么雅可比人在这种情况下是不可逆的。
https://stackoverflow.com/questions/64689237
复制相似问题