def gaussian_kde_1d(x, h, nb_bins, fft=True, bounds=None):
    (x_grid, bins) = get_bins_1d(x, nb_bins, bounds=bounds)
    x_range = x_grid[-1] - x_grid[0] # x_max - x_min
    delta_x = x_grid[1] - x_grid[0]
    # Generate kernel values
    # Eventually only generate values between 0 and 3 or 4 times h
    # (after <1.e-5) and use symetry...
    # Generate grid for kernel values
    ker_grid = np.arange( -x_range / 2., x_range / 2., delta_x)
    exp_fact = - .5 / h ** 2
    ker = np.exp(exp_fact * (ker_grid ** 2))
    # Normalize kernel
    s = np.sum(ker)
    if s == 0:
        print('Warning: window is too short...')
    ker = ker / s
    # Do convolution
    if fft:
        kde = fftconvolve(bins, ker)
    else:
        kde = convolve_1d(bins, ker)
    return (x_grid, kde)
Estimate probability from one dimensional samples, using a Gaussian
dataset/ETHPy150Open omangin/multimodal/multimodal/lib/kde1d.py/gaussian_kde_1d