ó
áp7]c           @  sr  d  d l  m Z d  d l m Z m Z d  d l Z d d l m Z d e	 f d „  ƒ  YZ
 e d k rnd  d	 l m Z d  d l j Z d  d l j j Z d  d
 l m Z e j d ƒ e j d d d ƒZ e j e ƒ Z e j d d d ƒ Z e j d e ƒ Z e
 e e ƒ Z e  e j! d ƒ ƒ e  d ƒ e j" d d d ƒ Z# e j$ ƒ  Z% e% j& d ƒ Z' e' j( e# e e# ƒ d ƒ e' j) d d ƒ e' j) d d ƒ e e j* d e j* d ƒ Z e j+ e ƒ Z e e j, d ƒ e j- d ƒ Z e j. d Z/ e j0 Z1 e j2 d ƒ Z e
 e e ƒ Z e  e j! e j3 d d g ƒ ƒ ƒ e j$ ƒ  e j( e d d … d f e d d … d f d ƒ d Z4 e j e j5 d ƒ d e j6 d ƒ d e4 ƒ Z7 e j e j5 d ƒ d e j6 d ƒ d e4 ƒ Z8 e j9 e7 e8 ƒ \ Z: Z; e j+ g  e e: j< ƒ  e; j< ƒ  ƒ D]* \ Z= Z> e j! e j3 e= e> g ƒ ƒ ^ qƒ Z? e j@ e7 e8 e? jA e4 e4 ƒ ƒ e jB ƒ  n  d S(   iÿÿÿÿ(   t   print_function(   t   lzipt   zipNi   (   t   kernelst   KDEc           B  s;   e  Z d  Z d d „ Z d „  Z d d „ Z d d „ Z RS(   sÖ   
    Kernel Density Estimator

    Parameters
    ----------
    x : array-like
        N-dimensional array from which the density is to be estimated
    kernel : Kernel Class
        Should be a class from *

    c         C  s¹   t  j | ƒ } | j d k r7 | d  d  … d  f } n  | j \ } } | d  k ra t j ƒ  } n  | d k rš t | t j ƒ rš t j	 | d | ƒ} qš n  | |  _
 | |  _ | |  _ d  S(   Ni   R   (   t   npt   asarrayt   ndimt   Nonet   shapeR   t   Gaussiant
   isinstancet   CustomKernelt   NdKernelt   kernelt   nt   x(   t   selfR   R   t   nobst   n_series(    (    sE   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kde2.pyt   __init__   s    		c         C  s   |  j  j |  j | ƒ S(   N(   R   t   densityR   (   R   R   (    (    sE   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kde2.pyR   (   s    t   scottc         C  s)   t  j g  | D] } |  j | ƒ ^ q ƒ S(   N(   R   t   arrayR   (   R   R   t   ht   xx(    (    sE   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kde2.pyt   __call__+   s    t	   silvermanc         C  s2   |  j  j } t j g  | D] } | | ƒ ^ q ƒ S(   N(   R   R   R   R   (   R   R   R   R   R   (    (    sE   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kde2.pyt   evaluate.   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   (    (    (    sE   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kde2.pyR   	   s
   	t   __main__(   t   random(   t   kdetestiŽ   gÍÌÌÌÌÌ@t   sizei2   iöÿÿÿi
   i   R   g¡l\?ð?g³A&9Ê?gš™™™™™¹?io   t   -i    gš™™™™™Ù?t	   eruptionst   waitingi   t   o(C   t
   __future__R    t   statsmodels.compat.pythonR   R   t   numpyR   t    R   t   objectR   R   R!   t   matplotlib.pyplott   pyplott   pltt$   statsmodels.nonparametric.bandwidthst   nonparametrict
   bandwidthst   bwt*   statsmodels.sandbox.nonparametric.testdataR"   t   seedt
   standard_tR   t   bw_silvermanR   t   linspacet   supportR
   t   kernt   kdet   printR   t   aranget   Xst   figuret   figt   add_subplott   axt   plott   set_ylimt   faithfulDataR   t   meant   stdR	   R   t   Hpit   HR   t   matrixt   n_gridt   mint   maxt   xspt   yspt   meshgridt   xrt   yrt   ravelt   xit   yit   kde_valst   contourt   reshapet   show(    (    (    sE   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/kde2.pyt   <module>   sR   *
 	"
3//	L