本文介绍了RBF插值失败:LinAlgError:奇异矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些分散的一维数据集,我想使用scipy.interpolate.Rbf函数对rbf函数进行插值.但是,对于一组特定的数据,似乎内插失败,给出LinAlgError:奇异矩阵错误. x-y数据为:

I have some scattered 1-d data sets and I want to interpolate with rbf function by using scipy.interpolate.Rbf function. However, for a specific set of data it seems that the interpolation fails giving LinAlgError: singular matrix error. The x-y data are:

x = numpy.array([169.,  161.,  153.,  146.,  139.,  134.,  129.,  127.,  123.,
        121.,  119.,  120.,  119.,  121.,  124.,  125.,  128.,  133.,
        137.,  141.,  143.]])

y = numpy.array([415.,  407.,  398.,  390.,  380.,  371.,  361.,  352.,  342.,
        333.,  321.,  313.,  304.,  296.,  286.,  277.,  268.,  259.,
        250.,  244.,  239.])

rbf = interpolate.Rbf(x, y, function='cubic',smooth=0.)
Traceback (most recent call last):

  File "<ipython-input-10-ddb099423b50>", line 1, in <module>
    rbf = interpolate.Rbf(x, y, function='cubic',smooth=0.)

  File "C:\WinPython-32bit-2.7.5.3\python-2.7.5\lib\site-packages\scipy\interpolate\rbf.py", line 207, in __init__
    self.nodes = linalg.solve(self.A, self.di)

  File "C:\WinPython-32bit-2.7.5.3\python-2.7.5\lib\site-packages\scipy\linalg\basic.py", line 100, in solve
    raise LinAlgError("singular matrix")

LinAlgError: singular matrix

如何避免此错误?是因为我的数据点彼此非常接近并且Gram矩阵无法求逆吗?如何插入这些数据?

How could I avoid this error? Is it because my data points are very close to one another and the Gram matrix cannot be inverted? How could I interpolate these data?

非常感谢.

推荐答案

正如@moarningsun指出的那样,每个x值不得等于其他任何x值.

As @moarningsun has already pointed out, every x-value must not equal any other x-value.

对于多维数据也是如此.不能出现n维采样点(即数据位置点)两次.

The same holds for multidimensional data. No n-dimensional sampling point (i.e. data location point) may appear twice.

这篇关于RBF插值失败:LinAlgError:奇异矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 02:08