问题
The following call:
rbf = Rbf(points[0], points[1], values,epsilon=2)
results in an error:
LinAlgError: singular matrix
with the following values:
In [3]: points
Out[3]:
(array([71, 50, 48, 84, 71, 74, 89, 76, 70, 77, 74, 79, 83, 71, 72, 78, 73,
84, 75, 65, 73, 82, 48, 86, 74, 86, 66, 74, 68, 74, 81, 74, 88, 66,
57, 50, 72, 86, 72, 92, 81, 67, 82, 78, 69, 70, 73, 71, 76, 72, 74,
75]),
array([32, 34, 4, 35, 1, 7, 47, 16, 37, 14, 65, 18, 32, 4, 3, 27, 25,
34, 18, 25, 6, 25, 34, 41, 16, 35, 44, 2, 32, 2, 37, 60, 45, 32,
33, 42, 54, 31, 18, 38, 24, 18, 45, 48, 9, 63, 56, 45, 9, 59, 5,
12]))
In [4]: values
Out[4]:
array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.,
1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])
What can I do to avoid it and still solve the interpolation problem?
回答1:
I think what you're trying to do is kernel density estimation. You can use scipy.stats.gaussian_kde for this:
import numpy as np
from scipy.stats import gaussian_kde
from matplotlib import pyplot as pp
# kernel density estimate of the PDF
kde = gaussian_kde(points)
# evaluate the estimated PDF on a grid
x,y = np.mgrid[40:101,-20:101]
z = kde((x.ravel(),y.ravel())).reshape(*x.shape)
# plot
fig,ax = pp.subplots(1,1)
ax.hold(True)
pc = ax.pcolor(x,y,z)
cb = pp.colorbar(pc)
cb.ax.set_ylabel('Probability density')
ax.plot(points[0],points[1],'o',mfc='w',mec='k')
pp.show()
The statsmodels module also has some more elaborate tools for kernel density estimation.
回答2:
I got same error. Finally I found why I get the error.
you have 2 point with same coordinate. (74,2) check the values have same coordinate in 28th, 30th.
In my thinking, even if you have same value on same point it emit singular matrix error.
来源:https://stackoverflow.com/questions/19237512/rbf-interpolation-linalgerror-singular-matrix