我有一个x,y
点分布,我得到KDE
到scipy.stats.gaussian_kde。这是我的代码,以及如何输出如下(在x,y
数据可以从here获得):积分二维核心密度估计
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()
坐标(x1, y1)
红点已经(像2D情节的每一个点)关联由f
(内核或KDE
)给出的值在0和0.42之间。我们说f(x1, y1) = 0.08
。
我需要在这些地区给予x
和y
到f
与积分限制整合地方f
评估为少比f(x1, y1)
,即:f(x, y)<0.08
。
对于我所看到python
可以执行功能并通过数值积分的一个维数组的整合,但我还没有看到任何东西,会让我一个2D阵列上执行数值积分(在f
内核)此外,我不知道我怎么会认识到由特定条件给出的区域(即:f(x, y)
小于给定值)
这可以完成吗?
令人惊讶的是简单的,我显然需要阅读一些统计数据。非常感谢你! – Gabriel
请注意,这个蒙特卡洛实现可能不正确。看到这里:http://stackoverflow.com/a/35903712/1391441 – Gabriel
@加布里埃尔我认为这个解决方案实际上是正确的这个问题。我看了你链接到的另一个问题。这是我的想法。这里有两种不同的整合界限。在这个问题中,你很清楚地表明你想要在f(x,y)
jcrudy