
    >h7                     n    S r SSKrSSKJr  SS jrS rS rS rS r	S	 r
S
 rS rS rS rS rS rS rg)a  
Module of kernels that are able to handle continuous as well as categorical
variables (both ordered and unordered).

This is a slight deviation from the current approach in
statsmodels.nonparametric.kernels where each kernel is a class object.

Having kernel functions rather than classes makes extension to a multivariate
kernel density estimation much easier.

NOTE: As it is, this module does not interact with the existing API
    N)erfc                    UR                  UR                  5      nUc4  [        R                  " [        R                  " U5      R                  5      n[        R
                  " UR                  5      U -  US-
  -  nX:H  nUSU -
  -  U   XE'   U$ )a  
The Aitchison-Aitken kernel, used for unordered discrete random variables.

Parameters
----------
h : 1-D ndarray, shape (K,)
    The bandwidths used to estimate the value of the kernel function.
Xi : 2-D ndarray of ints, shape (nobs, K)
    The value of the training set.
x : 1-D ndarray, shape (K,)
    The value at which the kernel density is being estimated.
num_levels : bool, optional
    Gives the user the option to specify the number of levels for the
    random variable.  If False, the number of levels is calculated from
    the data.

Returns
-------
kernel_value : ndarray, shape (nobs, K)
    The value of the kernel function at each training point for each var.

Notes
-----
See p.18 of [2]_ for details.  The value of the kernel L if :math:`X_{i}=x`
is :math:`1-\lambda`, otherwise it is :math:`\frac{\lambda}{c-1}`.
Here :math:`c` is the number of levels plus one of the RV.

References
----------
.. [*] J. Aitchison and C.G.G. Aitken, "Multivariate binary discrimination
       by the kernel method", Biometrika, vol. 63, pp. 413-420, 1976.
.. [*] Racine, Jeff. "Nonparametric Econometrics: A Primer," Foundation
       and Trends in Econometrics: Vol 3: No 1, pp1-88., 2008.
   )reshapesizenpasarrayuniqueones)hXix
num_levelskernel_valueidxs         tC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/nonparametric/kernels.pyaitchison_aitkenr      s{    F 
BGG	BZZ		" 2 23
77277#a':>:L
'CA,L    c                     UR                  UR                  5      nSSU -
  -  U [        X-
  5      -  -  nX:H  nUSU -
  -  U   X4'   U$ )a)  
The Wang-Ryzin kernel, used for ordered discrete random variables.

Parameters
----------
h : scalar or 1-D ndarray, shape (K,)
    The bandwidths used to estimate the value of the kernel function.
Xi : ndarray of ints, shape (nobs, K)
    The value of the training set.
x : scalar or 1-D ndarray of shape (K,)
    The value at which the kernel density is being estimated.

Returns
-------
kernel_value : ndarray, shape (nobs, K)
    The value of the kernel function at each training point for each var.

Notes
-----
See p. 19 in [1]_ for details.  The value of the kernel L if
:math:`X_{i}=x` is :math:`1-\lambda`, otherwise it is
:math:`\frac{1-\lambda}{2}\lambda^{|X_{i}-x|}`, where :math:`\lambda` is
the bandwidth.

References
----------
.. [*] Racine, Jeff. "Nonparametric Econometrics: A Primer," Foundation
       and Trends in Econometrics: Vol 3: No 1, pp1-88., 2008.
       http://dx.doi.org/10.1561/0800000009
.. [*] M.-C. Wang and J. van Ryzin, "A class of smooth estimators for
       discrete distributions", Biometrika, vol. 68, pp. 301-309, 1981.
      ?r   )r   r   abs)r   r   r   r   r   s        r   
wang_ryzinr   D   sV    B 
BGG	B!a%=ARV$45L
'CA,Lr   c                     S[         R                  " S[         R                  -  5      -  [         R                  " X-
  S-  * U S-  S-  -  5      -  $ )a  
Gaussian Kernel for continuous variables
Parameters
----------
h : 1-D ndarray, shape (K,)
    The bandwidths used to estimate the value of the kernel function.
Xi : 1-D ndarray, shape (K,)
    The value of the training set.
x : 1-D ndarray, shape (K,)
    The value at which the kernel density is being estimated.

Returns
-------
kernel_value : ndarray, shape (nobs, K)
    The value of the kernel function at each training point for each var.
      ?   g       @r   sqrtpiexpr   r   r   s      r   gaussianr!   l   sC    " RUU##rvv{ladRi.H'IIIr   c                     X-
  U -  nSU[         R                  " U5      S:  '   SS[         R                  " U5      S-  -
  S-  -  $ )a  
Tricube Kernel for continuous variables
Parameters
----------
h : 1-D ndarray, shape (K,)
    The bandwidths used to estimate the value of the kernel function.
Xi : 1-D ndarray, shape (K,)
    The value of the training set.
x : 1-D ndarray, shape (K,)
    The value at which the kernel density is being estimated.

Returns
-------
kernel_value : ndarray, shape (nobs, K)
    The value of the kernel function at each training point for each var.
r   r   g?   )r   r   )r   r   r   us       r   tricuber%      sF    " 
1AAbffQi!mRVVAY\)A---r   c                     S[         R                  " S[         R                  -  5      -  [         R                  " X-
  S-  * U S-  S-  -  5      -  $ )z+Calculates the Gaussian Convolution Kernel r      r   g      @r   r    s      r   gaussian_convolutionr(      sA    RUU##rvv!mq!tby.I'JJJr   c                     [         R                  " UR                  5      n[         R                  " U5       H  nU[	        XU5      [	        XU5      -  -  nM!     U$ Nr   zerosr   r
   r   )r   r   Xjorderedr   s        r   wang_ryzin_convolutionr/      sL     hhrwwGYYr]:aQ'*QA*>>>  Nr   c           
          [         R                  " U5      n[         R                  " UR                  5      nUR                  nU H  nU[	        XXeS9[	        XXeS9-  -  nM     U$ N)r   )r   r
   r,   r   r   )r   r   r-   Xi_valsr.   r   r   s          r   aitchison_aitken_convolutionr3      s`    iimGhhrwwGJ#A1D#A1DE 	E  Nr   c           	      b    SU -  S[        X!-
  U [        R                  " S5      -  -  5      -   -  $ )Nr   r   r   )r   r   r   r    s      r   gaussian_cdfr5      s.    7a#qv!bggaj.9::;;r   c           	          [        U5      n[        R                  " U5      n[        R                  " UR                  5      nUR                  nU H  nXb::  d  M
  U[        XXeS9-  nM     U$ r1   )intr   r
   r,   r   r   )r   r   x_ur2   r.   r   r   s          r   aitchison_aitken_cdfr9      s[    
c(CiimGhhrwwGJ8'qHHG  Nr   c                     [         R                  " UR                  5      n[         R                  " U5       H  nXB::  d  M
  U[	        XU5      -  nM     U$ r*   r+   )r   r   r8   r.   r   s        r   wang_ryzin_cdfr;      sC    hhrwwGYYr]8z!++G  Nr   c                 6    SX-
  -  [        XU5      -  U S-  -  $ )Nr   )r!   r    s      r   
d_gaussianr=      s#    <(1!,,q!t33r   c                 b    [         R                  " UR                  5      nX:g  nX@-  nXT   X4'   U$ )zf
A version for the Aitchison-Aitken kernel for nonparametric regression.

Suggested by Li and Racine.
)r   r   r   )r   r   r   r   ixinDoms         r   aitchison_aitken_regrA      s4     77277#L	BFEyLr   c                 "    U [        X-
  5      -  $ )zk
A version for the Wang-Ryzin kernel for nonparametric regression.

Suggested by Li and Racine in [1] ch.4
)r   r    s      r   wang_ryzin_regrC      s     BFr   r*   )__doc__numpyr   scipy.specialr   r   r   r!   r%   r(   r/   r3   r5   r9   r;   r=   rA   rC    r   r   <module>rH      sW     *Z%PJ(.,K
<	4

r   