- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我不明白 curve_fit
无法估计参数的协方差,因此引发了下面的 OptimizeWarning
。以下 MCVE 解释了我的问题:
MCVE python 片段
from scipy.optimize import curve_fit
func = lambda x, a: a * x
popt, pcov = curve_fit(f = func, xdata = [1], ydata = [1])
print(popt, pcov)
输出
\python-3.4.4\lib\site-packages\scipy\optimize\minpack.py:715:
OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)
[ 1.] [[ inf]]
对于 a = 1
,该函数完全适合 xdata
和 ydata
。为什么误差/方差不是 0
或接近 0
的值,而是 inf
?
这句话来自 curve_fit
SciPy Reference Guide :
If the Jacobian matrix at the solution doesn’t have a full rank, then ‘lm’ method returns a matrix filled with np.inf, on the other hand ‘trf’ and ‘dogbox’ methods use Moore-Penrose pseudoinverse to compute the covariance matrix.
那么,根本问题是什么?为什么解的雅可比矩阵没有满秩?
最佳答案
参数协方差的公式 ( Wikipedia ) 在分母中包含自由度数。自由度计算为(数据点数)-(参数数),在您的示例中为 1 - 1 = 0。和 this是 SciPy 在除以它之前检查自由度数的地方。
使用 xdata = [1, 2], ydata = [1, 2]
您将获得零协方差(请注意,模型仍然完全适合:完全适合不是问题)。
如果样本大小 N 为 1(样本方差的公式在分母中有 (N-1)),这与未定义样本方差是同一类问题。如果我们只从总体中取出 size=1 个样本,我们不会将方差估计为零,我们对方差一无所知。
关于python - 如果参数完全符合,为什么 `curve_fit` 不能估计参数的协方差?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41725377/
在我的设置中,我试图有一个界面 Table继承自 Map (因为它主要用作 map 的包装器)。两个类继承自 Table - 本地和全局。全局的将有一个可变的映射,而本地的将有一个只有本地条目的映射。
Rust Nomicon 有 an entire section on variance除了关于 Box 的这一小节,我或多或少地理解了这一点和 Vec在 T 上(共同)变体. Box and Vec
我是一名优秀的程序员,十分优秀!