
    M/Ph                         d dl Zd dlmZ d dlmZ d dlmZ ddZddZ	ddZ
dd	Ze	e
ed
Z ed                     ee                                                              d             ZdS )    N)scoreatpercentile)Substitution)kernels   c                     d}t          | d          t          | d          z
  |z  }t          j        | dd          }|dk    rt          j        ||          S |S )z
    Returns the smaller of std(X, ddof=1) or normalized IQR(X) over axis 0.

    References
    ----------
    Silverman (1986) p.47
    g/$?K   r   r      )axisddof)r   npstdminimum)x
percentile	normalizeIQRstd_devs        d/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/nonparametric/bandwidths.py_select_sigmar      sc     IQ##&72&>&>>)
KCfQQQ'''G
Qwwz'3'''    c                 T    t          |           }t          |           }d|z  |dz  z  S )a*  
    Scott's Rule of Thumb

    Parameters
    ----------
    x : array_like
        Array for which to get the bandwidth
    kernel : CustomKernel object
        Unused

    Returns
    -------
    bw : float
        The estimate of the bandwidth

    Notes
    -----
    Returns 1.059 * A * n ** (-1/5.) where ::

       A = min(std(x, ddof=1), IQR/1.349)
       IQR = np.subtract.reduce(np.percentile(x, [75,25]))

    References
    ----------

    Scott, D.W. (1992) Multivariate Density Estimation: Theory, Practice, and
        Visualization.
    gl?皙ɿr   lenr   kernelAns       r   bw_scottr      s/    : 	aAAA19qT{""r   c                 T    t          |           }t          |           }d|z  |dz  z  S )a  
    Silverman's Rule of Thumb

    Parameters
    ----------
    x : array_like
        Array for which to get the bandwidth
    kernel : CustomKernel object
        Unused

    Returns
    -------
    bw : float
        The estimate of the bandwidth

    Notes
    -----
    Returns .9 * A * n ** (-1/5.) where ::

       A = min(std(x, ddof=1), IQR/1.349)
       IQR = np.subtract.reduce(np.percentile(x, [75,25]))

    References
    ----------

    Silverman, B.W. (1986) `Density Estimation.`
    g?r   r   r   s       r   bw_silvermanr!   <   s/    8 	aAAA6A$Kr   c                     |t          j                    }|j        }t          |           }t	          |           }||z  |dz  z  S )a{  
    Plug-in bandwidth with kernel specific constant based on normal reference.

    This bandwidth minimizes the mean integrated square error if the true
    distribution is the normal. This choice is an appropriate bandwidth for
    single peaked distributions that are similar to the normal distribution.

    Parameters
    ----------
    x : array_like
        Array for which to get the bandwidth
    kernel : CustomKernel object
        Used to calculate the constant for the plug-in bandwidth.
        The default is a Gaussian kernel.

    Returns
    -------
    bw : float
        The estimate of the bandwidth

    Notes
    -----
    Returns C * A * n ** (-1/5.) where ::

       A = min(std(x, ddof=1), IQR/1.349)
       IQR = np.subtract.reduce(np.percentile(x, [75,25]))
       C = constant from Hansen (2009)

    When using a Gaussian kernel this is equivalent to the 'scott' bandwidth up
    to two decimal places. This is the accuracy to which the 'scott' constant is
    specified.

    References
    ----------

    Silverman, B.W. (1986) `Density Estimation.`
    Hansen, B.E. (2009) `Lecture Notes on Nonparametrics.`
    Nr   )r   Gaussiannormal_reference_constantr   r   )r   r   Cr   r   s        r   bw_normal_referencer&   ]   sK    N ~!##(AaAAAq51;r   )scott	silvermannormal_referencez, c                     |                                 }|t          vrt          d|z            t          |         | |          }t          j        |dk              rd}t          |          |S )a  
    Selects bandwidth for a selection rule bw

    this is a wrapper around existing bandwidth selection rules

    Parameters
    ----------
    x : array_like
        Array for which to get the bandwidth
    bw : str
        name of bandwidth selection rule, currently supported are:
        %s
    kernel : not used yet

    Returns
    -------
    bw : float
        The estimate of the bandwidth
    zBandwidth %s not understoodr   zSelected KDE bandwidth is 0. Cannot estimate density. Either provide the bandwidth during initialization or use an alternative method.)lowerbandwidth_funcs
ValueErrorr   anyRuntimeError)r   bwr   	bandwidtherrs        r   select_bandwidthr3      sw    * 
B	  6;<<<#Av..I	vi1n ' 3r   )r   )N)numpyr   scipy.statsr   statsmodels.compat.pandasr   !statsmodels.sandbox.nonparametricr   r   r   r!   r&   r,   joinsortedkeysr3    r   r   <module>r<      s       ) ) ) ) ) ) 2 2 2 2 2 2 5 5 5 5 5 5   &# # # #B       B, , , ,j +  dii3355667788  98  r   