#NEWLINE# def kdensityfft( X , kernel = 'gau' , bw = 'normal_reference' , weights = None , gridsize = None , adjust = 1 , clip = ( ( - np . inf ) , np . inf ) , cut = 3 , retgrid = True ) : #NEWLINE# #INDENT# '\n    Rosenblatt-Parzen univariate kernel density estimator\n\n    Parameters\n    ----------\n    X : array-like\n        The variable for which the density estimate is desired.\n    kernel : str\n        ONLY GAUSSIAN IS CURRENTLY IMPLEMENTED.\n        "bi" for biweight\n        "cos" for cosine\n        "epa" for Epanechnikov, default\n        "epa2" for alternative Epanechnikov\n        "gau" for Gaussian.\n        "par" for Parzen\n        "rect" for rectangular\n        "tri" for triangular\n    bw : str, float\n        "scott" - 1.059 * A * nobs ** (-1/5.), where A is min(std(X),IQR/1.34)\n        "silverman" - .9 * A * nobs ** (-1/5.), where A is min(std(X),IQR/1.34)\n        If a float is given, it is the bandwidth.\n    weights : array or None\n        WEIGHTS ARE NOT CURRENTLY IMPLEMENTED.\n        Optional  weights. If the X value is clipped, then this weight is\n        also dropped.\n    gridsize : int\n        If gridsize is None, min(len(X), 512) is used. Note that the provided\n        number is rounded up to the next highest power of 2.\n    adjust : float\n        An adjustment factor for the bw. Bandwidth becomes bw * adjust.\n        clip : tuple\n        Observations in X that are outside of the range given by clip are\n        dropped. The number of observations in X is then shortened.\n    cut : float\n        Defines the length of the grid past the lowest and highest values of X\n        so that the kernel goes to zero. The end points are\n        -/+ cut*bw*{X.min() or X.max()}\n    retgrid : bool\n        Whether or not to return the grid over which the density is estimated.\n\n    Returns\n    -------\n    density : array\n        The densities estimated at the grid points.\n    grid : array, optional\n        The grid points at which the density is estimated.\n\n    Notes\n    -----\n    Only the default kernel is implemented. Weights aren\'t implemented yet.\n    This follows Silverman (1982) with changes suggested by Jones and Lotwick\n    (1984). However, the discretization step is replaced by linear binning\n    of Fan and Marron (1994). This should be extended to accept the parts\n    that are dependent only on the data to speed things up for\n    cross-validation.\n\n    References\n    ---------- ::\n\n    Fan, J. and J.S. Marron. (1994) `Fast implementations of nonparametric\n        curve estimators`. Journal of Computational and Graphical Statistics.\n        3.1, 35-56.\n    Jones, M.C. and H.W. Lotwick. (1984) `Remark AS R50: A Remark on Algorithm\n        AS 176. Kernal Density Estimation Using the Fast Fourier Transform`.\n        Journal of the Royal Statistical Society. Series C. 33.1, 120-2.\n    Silverman, B.W. (1982) `Algorithm AS 176. Kernel density estimation using\n        the Fast Fourier Transform. Journal of the Royal Statistical Society.\n        Series C. 31.2, 93-9.\n    ' #NEWLINE# X = np . asarray ( X ) #NEWLINE# X = X [ np . logical_and ( ( X > clip [ 0 ] ) , ( X < clip [ 1 ] ) ) ] #NEWLINE# kern = kernel_switch [ kernel ] ( ) #NEWLINE# try : #NEWLINE# #INDENT# bw = float ( bw ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# bw = bandwidths . select_bandwidth ( X , bw , kern ) #NEWLINE# #UNINDENT# bw *= adjust #NEWLINE# nobs = len ( X ) #NEWLINE# if ( gridsize == None ) : #NEWLINE# #INDENT# gridsize = np . max ( ( nobs , 512.0 ) ) #NEWLINE# #UNINDENT# gridsize = ( 2 ** np . ceil ( np . log2 ( gridsize ) ) ) #NEWLINE# a = ( np . min ( X ) - ( cut * bw ) ) #NEWLINE# b = ( np . max ( X ) + ( cut * bw ) ) #NEWLINE# ( grid , delta ) = np . linspace ( a , b , gridsize , retstep = True ) #NEWLINE# RANGE = ( b - a ) #NEWLINE# binned = ( fast_linbin ( X , a , b , gridsize ) / ( delta * nobs ) ) #NEWLINE# y = forrt ( binned ) #NEWLINE# zstar = ( silverman_transform ( bw , gridsize , RANGE ) * y ) #NEWLINE# f = revrt ( zstar ) #NEWLINE# if retgrid : #NEWLINE# #INDENT# return ( f , grid , bw ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( f , bw )