ó
áp7]c           @   s»   d  d l  m Z d  d l Z d  d l m Z d  d l m Z d „  Z	 d d „ Z d d „ Z e j d „ Z i e d	 6e d
 6e d 6Z d „  Z e j d j e e j ƒ  ƒ ƒ f ;_ d S(   iÿÿÿÿ(   t   divisionN(   t   scoreatpercentile(   t   kernelsc         C   sK   d } t  |  d ƒ t  |  d ƒ | } t j t j |  d d d d ƒ| ƒ S(   sŠ   
    Returns the smaller of std(X, ddof=1) or normalized IQR(X) over axis 0.

    References
    ----------
    Silverman (1986) p.47
    g/Ý$•õ?iK   i   t   axisi    t   ddofi   (   t   sapt   npt   minimumt   std(   t   Xt	   normalizet   IQR(    (    sC   lib/python2.7/site-packages/statsmodels/nonparametric/bandwidths.pyt   _select_sigma   s    	 c         C   s(   t  |  ƒ } t |  ƒ } d | | d S(   s*  
    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.
    g‹lçû©ñð?gš™™™™™É¿(   R   t   len(   t   xt   kernelt   At   n(    (    sC   lib/python2.7/site-packages/statsmodels/nonparametric/bandwidths.pyt   bw_scott   s    c         C   s(   t  |  ƒ } t |  ƒ } d | | d S(   s÷  
    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ÍÌÌÌÌÌì?gš™™™™™É¿(   R   R   (   R   R   R   R   (    (    sC   lib/python2.7/site-packages/statsmodels/nonparametric/bandwidths.pyt   bw_silverman9   s    c         C   s1   | j  } t |  ƒ } t |  ƒ } | | | d S(   sQ  
    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.

    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.`
    gš™™™™™É¿(   t   normal_reference_constantR   R   (   R   R   t   CR   R   (    (    sC   lib/python2.7/site-packages/statsmodels/nonparametric/bandwidths.pyt   bw_normal_referenceZ   s    &	t   scottt	   silvermant   normal_referencec         C   s<   | j  ƒ  } | t k r+ t d | ƒ ‚ n  t | |  | ƒ S(   sš  
    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 : string
        name of bandwidth selection rule, currently supported are:
        %s
    kernel : not used yet

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

    s   Bandwidth %s not understood(   t   lowert   bandwidth_funcst
   ValueError(   R   t   bwR   (    (    sC   lib/python2.7/site-packages/statsmodels/nonparametric/bandwidths.pyt   select_bandwidth’   s    s   , (   t
   __future__R    t   numpyR   t   scipy.statsR   R   t!   statsmodels.sandbox.nonparametricR   R   t   NoneR   R   t   GaussianR   R   R   t   __doc__t   joint   sortedt   keys(    (    (    sC   lib/python2.7/site-packages/statsmodels/nonparametric/bandwidths.pyt   <module>   s   	!!1
	