python - scipy结果线性插值结果不一致

标签 python numpy scipy interpolation

我需要对包含'n' 自变量和因变量的数据执行线性插值。我目前正在使用 scipy.interpolate.LinearNDInterpolator 来执行插值。但是,当我通过将(变量的)所有值乘以常量来更改数据集的范围时,插值后的结果完全改变。

让我用一个具体的例子来说明这一点:

 X = [[0.00000000e+00, 1.00000000e+00], [0.00000000e+00, 8.00000000e+00], [0.00000000e+00, 1.60000000e+01], [0.00000000e+00, 3.20000000e+01], 
      [0.00000000e+00, 6.40000000e+01], [0.00000000e+00, 1.28000000e+02], [1.00000000e-06, 1.00000000e+00], [1.00000000e-06, 8.00000000e+00], 
      [1.00000000e-06, 1.60000000e+01], [1.00000000e-06, 3.20000000e+01], [1.00000000e-06, 6.40000000e+01], [1.00000000e-06, 1.28000000e+02], 
      [1.00000000e-06, 2.56000000e+02], [1.00000000e-06, 5.12000000e+02], [1.00000000e-05, 1.00000000e+00], [1.00000000e-05, 8.00000000e+00], 
      [1.00000000e-05, 1.60000000e+01], [1.00000000e-05, 3.20000000e+01], [1.00000000e-05, 6.40000000e+01], [1.00000000e-05, 1.28000000e+02], 
      [1.00000000e-05, 2.56000000e+02], [1.00000000e-05, 5.12000000e+02], [1.00000000e-04, 1.00000000e+00], [1.00000000e-04, 8.00000000e+00], 
      [1.00000000e-04, 1.60000000e+01], [1.00000000e-04, 3.20000000e+01], [1.00000000e-04, 6.40000000e+01], [1.00000000e-04, 1.28000000e+02], 
      [1.00000000e-04, 2.56000000e+02], [1.00000000e-04, 5.12000000e+02], [1.00000000e-03, 1.00000000e+00], [1.00000000e-03, 8.00000000e+00], 
      [1.00000000e-03, 1.60000000e+01], [1.00000000e-03, 3.20000000e+01], [1.00000000e-03, 6.40000000e+01], [1.00000000e-03, 1.28000000e+02], 
      [1.00000000e-02, 1.00000000e+00], [1.00000000e-02, 8.00000000e+00], [1.00000000e-02, 1.60000000e+01], [1.00000000e-02, 3.20000000e+01], 
      [1.00000000e-02, 6.40000000e+01], [1.00000000e-02, 1.28000000e+02]]
 y = [0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, 6.99000000e-17, 5.60000000e-16, 1.12011400e-15, 2.24034300e-15, 
      4.48080000e-15, 7.56193140e-14, 2.17896343e-13, 5.02450401e-13, 6.99000000e-16, 5.60000000e-15, 1.12011430e-14, 2.24034290e-14, 4.48080000e-14, 8.96171430e-14, 
      1.79235429e-13, 3.58472001e-13, 6.99000000e-15, 5.60000000e-14, 1.12011429e-13, 2.24034286e-13, 4.48080000e-13, 8.96171429e-13, 1.79235429e-12, 3.58472000e-12, 
      6.99000000e-14, 5.60000000e-13, 1.10000000e-12, 2.20000000e-12, 4.50000000e-12, 9.00000000e-12, 6.99000000e-13, 5.60000000e-12, 1.12000000e-11, 2.24000000e-11, 
      4.48000000e-11, 8.95000000e-11]

当我对值 [7.10000000e-05, 18] 执行插值时,我得到结果 7.95281146e-14。如果我将第一列乘以 10^3,将结果列乘以 10^12,那么我得到的结果将完全不同。我得到的 0.09352 相当于 9.352e-14

  • 有人可以解释为什么 scipy 在这些情况下给出不同的结果吗?
  • 以下哪个结果是正确的? (我尝试使用 Excel,但我很快意识到 scipy 使用不同的技术)。
  • 我应该如何解决这个问题?

最佳答案

正如罗伯特·科恩(Robert Kern)上面所说,答案是两个答案都是正确的。然而,他们回答了不同的问题。

当在点 (x, y) 处插入分散数据时,算法必须知道以下问题的答案:“哪个数据点最接近 (x, y)。现在,最明显的方法是使用欧几里德距离,这也是算法中使用的 Delaunay 三角剖分的基础:

distance = sqrt((x[i] - x)**2 + (y[i] - y)**2)

现在,如果将 x 坐标缩放 1e3,“哪个点最接近”问题的答案显然会发生变化,因为 y 坐标变得不再那么重要。

正确的选择是使用欧几里得距离有意义的缩放比例。如果您正在研究物理,则 x 和 y 坐标应具有相同的单位或均为无量纲。

关于python - scipy结果线性插值结果不一致,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16414704/

相关文章:

python - 在 cygwin 中安装 scipy

python - 如何为 selenium 设置 geckodriver?

python - 无法为python安装pygame

python - 计算数组列表的计数百分比

python - 如何使我的 pylab.poly1d(fit) 通过零?

python - Numpy bool 数组上的 bool 运算符之和(错误?)

python - scipy 中的卡方与 SPSS 中的结果不同

python - 输入命令将输入​​作为 int 而不是 Python 中的 str

python - Pyspark BinaryClassficationROC 下的指标区域

python - 使用 scipy.signal.find_peaks_cwt