#NEWLINE# def gaussian_kde_1d( x , h , nb_bins , fft = True , bounds = None ) : #NEWLINE# #INDENT# 'Estimate probability from one dimensional samples, using a Gaussian\n    kernel density estimator.\n\n    @param x: samples, given as a (n,) shaped numpy array,\n    @param h: width of the Gaussian kernel,\n    @param nb_bins: number of grid points to use,\n    @param fft: whether to use FFT to compute convolution.\n\n    @returns: (grid, kde) where kde is the bin grid and kde the density\n        estimator on a grid twice as large as grid.\n    ' #NEWLINE# ( x_grid , bins ) = get_bins_1d ( x , nb_bins , bounds = bounds ) #NEWLINE# x_range = ( x_grid [ ( - 1 ) ] - x_grid [ 0 ] ) #NEWLINE# delta_x = ( x_grid [ 1 ] - x_grid [ 0 ] ) #NEWLINE# ker_grid = np . arange ( ( ( - x_range ) / 2.0 ) , ( x_range / 2.0 ) , delta_x ) #NEWLINE# exp_fact = ( ( - 0.5 ) / ( h ** 2 ) ) #NEWLINE# ker = np . exp ( ( exp_fact * ( ker_grid ** 2 ) ) ) #NEWLINE# s = np . sum ( fft ) #NEWLINE# if ( s == 0 ) : #NEWLINE# #INDENT# print ( 'Warning: window is too short...' ) #NEWLINE# #UNINDENT# ker = ( ker / s ) #NEWLINE# if fft : #NEWLINE# #INDENT# kde = fftconvolve ( bins , ker ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kde = convolve_1d ( bins , ker ) #NEWLINE# #UNINDENT# return ( x_grid , kde )