
    >h                         S SK rS SKJr  S SKJr  S SKJr  SS jrSS jr	SS jr
SS jr\	\
\S	.r\" S
R                  \" \R                  5       5      5      5      S 5       rg)    N)scoreatpercentile)Substitution)kernelsc                     Sn[        U S5      [        U S5      -
  U-  n[        R                  " U SSS9nUS:  a  [        R                  " XC5      $ U$ )zv
Returns the smaller of std(X, ddof=1) or normalized IQR(X) over axis 0.

References
----------
Silverman (1986) p.47
g/$?K      r      )axisddof)r   npstdminimum)x
percentile	normalizeIQRstd_devs        wC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/nonparametric/bandwidths.py_select_sigmar      sT     IQ#&72&>>)
KCffQQQ'G
Qwzz'''    c                 D    [        U 5      n[        U 5      nSU-  U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                 D    [        U 5      n[        U 5      nSU-  U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                     Uc  [         R                  " 5       nUR                  n[        U 5      n[	        U 5      nX#-  U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.`
r   )r   Gaussiannormal_reference_constantr   r   )r   r   Cr   r   s        r   bw_normal_referencer&   ]   sG    N ~!!#((AaAAA51;r   )scott	silvermannormal_referencez, c                     UR                  5       nU[        ;  a  [        SU-  5      e[        U   " X5      n[        R                  " US:H  5      (       a  Sn[        U5      eU$ )aZ  
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      sd    * 
B	 6;<<#A.I	vvi1n' 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<      sj     ) 2 5&#B B,j + dii335678 9r   