from KDEpy import FFTKDE
from scipy.stats import norm

# Generate a distribution and some multimodal data
dist1 = norm(loc=0, scale=1)
dist2 = norm(loc=10, scale=1)
data = np.hstack([dist1.rvs(2**8), dist2.rvs(2**8)])

# Compute density estimates using 'silverman'
x, y = FFTKDE(kernel='gaussian', bw='silverman').fit(data).evaluate()
plt.plot(x, y, label='KDE /w silverman')

# Compute density estimates using 'ISJ' - Improved Sheather Jones
y = FFTKDE(kernel='gaussian', bw='ISJ').fit(data).evaluate(x)
plt.plot(x, y, label='KDE /w ISJ')

plt.plot(x, (dist1.pdf(x) + dist2.pdf(x))/2, label='True pdf')
plt.grid(True, ls='--', zorder=-15); plt.legend();