我有一个通过scipy.stats.gaussian_kdex,y
获得的点分布。这是我的代码和输出的样子(数据可以从这里获得):KDE
x,y
import numpy as np
from scipy import stats
# Obtain data from file.
data = np.loadtxt('data.dat', unpack=True)
m1, m2 = data[0], data[1]
xmin, xmax = min(m1), max(m1)
ymin, ymax = min(m2), max(m2)
# Perform a kernel density estimate (KDE) on the data
x, y = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]
positions = np.vstack([x.ravel(), y.ravel()])
values = np.vstack([m1, m2])
kernel = stats.gaussian_kde(values)
f = np.reshape(kernel(positions).T, x.shape)
# Define the number that will determine the integration limits
x1, y1 = 2.5, 1.5
# Perform integration?
# Plot the results:
import matplotlib.pyplot as plt
# Set limits
plt.xlim(xmin,xmax)
plt.ylim(ymin,ymax)
# KDE density plot
plt.imshow(np.rot90(f), cmap=plt.cm.gist_earth_r, extent=[xmin, xmax, ymin, ymax])
# Draw contour lines
cset = plt.contour(x,y,f)
plt.clabel(cset, inline=1, fontsize=10)
plt.colorbar()
# Plot point
plt.scatter(x1, y1, c='r', s=35)
plt.show()
带有坐标的红点(与 2D 图中的每个点一样)具有由(内核或)给出的 0 到 0.42 之间(x1, y1)
的关联值。让我们这么说吧。f
KDE
f(x1, y1) = 0.08
我需要与那些评估为小于f
的区域中的积分限制相结合,即:.x
y
f
f(x1, y1)
f(x, y)<0.08
对于我所看到python
的可以通过数值积分来执行函数和一维数组的积分,但是我还没有看到任何可以让我在二维数组(f
内核)上执行数值积分的东西此外,我不确定如何我什至会识别该特定条件给出的区域(即:f(x, y)
小于给定值)
这完全可以做到吗?