如何整合核密度估计

How to integrate kernel density estimation

我有资料

from scipy.stats.kde import gaussian_kde
import numpy as np
from scipy import integrate

data1 = np.linspace(0,1,50)
data2 = np.linspace(0.1,0.9,50)
data3 = np.linspace(0,0.7,50)
data4 = np.linspace(0.1,1,50)

我需要对所有变量进行密度乘法积分

kde1 = gaussian_kde(data1)
kde2 = gaussian_kde(data2)
kde3 = gaussian_kde(data3)
kde4 = gaussian_kde(data4)


print(integrate.nquad(lambda x1,x2,x3,x4: kde1(x1)*kde2(x2)*kde3(x3)*kde4(x4),
                            [[-1,1],[-1,1],[-1,1],[-1,1]])[0])

我认为这是正确的解决方案,但它的工作速度非常慢(超过 10 分钟)。有没有可能让它变得更快?

问题可以用蒙特卡洛积分法解决

例如

from skmonaco import mcquad
mcquad(lambda x_y: x_y[0]*x_y[1], # integrand
     xl=[0.,0.],xu=[1.,1.], # lower and upper limits of integration
     npoints=100000 # number of points
     )

结果: (0.24959359250821114, 0.0006965923631156234)