def KDE_entropy(x):
'''
Estimate the entropy H(X) from samples {x_i}_{i=1}^N
Using Kernel Density Estimator (KDE) and resubstitution
Input: x: 2D list of size N*d_x
Output: one number of H(X)
'''
N = len(x)
d = len(x[0])
local_est = np.zeros(N)
for i in range(N):
kernel = sst.gaussian_kde(x.transpose())
local_est[i] = kernel.evaluate(x[i].transpose())
return -np.mean(map(log,local_est))
评论列表
文章目录