Python 高斯KDE分布的并集体积交(IoU)

Python 高斯KDE分布的并集体积交(IoU),python,3d,union,intersection,similarity,Python,3d,Union,Intersection,Similarity,我想在变量分布之间创建一个相似性指数,并考虑使用高斯KDE的联合体积交集(IoU)来调整数据密度。我在这里举个例子 我有以下分配: import numpy as np import matplotlib.pyplot as plt import scipy.stats as st x1 = np.linspace(0,10,100) y1 = 2*x1+2+(2*np.random.randn(100)) x2 = np.linspace(0,10,100) y2 = 3*x1+1+(2*

我想在变量分布之间创建一个相似性指数,并考虑使用高斯KDE的联合体积交集(IoU)来调整数据密度。我在这里举个例子

我有以下分配:

import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as st

x1 = np.linspace(0,10,100)
y1 = 2*x1+2+(2*np.random.randn(100))

x2 = np.linspace(0,10,100)
y2 = 3*x1+1+(2*np.random.randn(100))

plt.scatter(x1, y1)
plt.scatter(x2, y2)
plt.title("Example of distributions")
plt.xlabel("x")
plt.ylabel("y")

请记住,分布并不总是遵循线性关系;它们可以有任何形状。我在下面的链接中找到了一种将高斯KDE调整到每个分布的方法,生成以下结果:

deltaX = (np.max((x1,x2)) - np.min((x1,x2)))/10
deltaY = (np.max((y1,y2)) - np.min((y1,y2)))/10
xmin = np.min((x1,x2)) - deltaX
xmax = np.max((x1,x2)) + deltaX
ymin = np.min((y1,y2)) - deltaY
ymax = np.max((y1,y2)) + deltaY
print(xmin, xmax, ymin, ymax)
xx, yy = np.mgrid[xmin:xmax:100j, ymin:ymax:100j]

positions = np.vstack([xx.ravel(), yy.ravel()])
values1 = np.vstack([x1, y1])
kernel1 = st.gaussian_kde(values1)
f1 = np.reshape(kernel1(positions).T, xx.shape)
f1_norm = f1/np.sum(f1)

values2 = np.vstack([x2, y2])
kernel2 = st.gaussian_kde(values2)
f2 = np.reshape(kernel2(positions).T, xx.shape)
f2_norm = f2/np.sum(f2)

fig = plt.figure(figsize=(8,8))
ax = fig.gca()
ax.set_xlim(xmin, xmax)
ax.set_ylim(ymin, ymax)
cset1 = ax.contour(xx, yy, f1_norm, colors='k')
cset2 = ax.contour(xx, yy, f2_norm, colors='r')
ax.set_xlabel('X')
ax.set_ylabel('Y')
plt.title('2D Gaussian Kernel density estimation')

链接到此脚本:

现在,我将高斯KDE调整到我的数据密度,由变量f1_norm和f2_norm表示(我对它们进行了归一化,以便可以在体积方面进行比较)。现在,最后一步是使用f1_范数和f2_范数计算这两个分布的IoU。我的想法是,这些高斯分布重叠越多,分布就越相似。然而,我发现的IoU计算通常与二维的正方形(边界框)有关。有没有办法把这个计算推广到三维和任何物体上