ó
—W[c           @   sÁ   d  d l  Z d d l m Z d  d l m Z d  d l Z d d l m Z	 e j
 d „  ƒ Z d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d S(   iÿÿÿÿNi   (   t   range(   t   assert_array_equal(   t
   algorithmsc           C   s#   t  j j t t t d ƒ ƒ ƒ d  S(   Nt   test_algorithms(   t   npt   randomt   seedt   sumt   mapt   ord(    (    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyR   
   s    c         C   sx   t  j d ƒ } d } t j | d | ƒ} t | t  j | ƒ ƒ t j | d | d t  j ƒ} t | t  j | ƒ ƒ d S(   s=   Test that bootstrapping gives the right answer in dumb cases.i
   i   t   n_boott   funcN(   R   t   onest   algot	   bootstrapR   t   median(   R   t   a_onesR
   t   out1t   out2(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap   s    c         C   sp   t  j j d ƒ } t j | ƒ } t | ƒ d k s9 t ‚ d } t j | d | ƒ} t | ƒ | k sl t ‚ d S(   s6   Test that we get a bootstrap array of the right shape.iè  i'  id   R
   N(   R   R   t   randnR   R   t   lent   AssertionError(   R   t   a_normt   outR
   (    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_length   s    c         C   sn   t  j j d ƒ } | j ƒ  | j ƒ  } } t j | ƒ } | | j ƒ  k sR t ‚ | | j ƒ  k sj t ‚ d S(   sC   Test that boostrapping a random array stays within the right range.iè  N(   R   R   R   t   mint   maxR   R   R   (   R   R   t   amint   amaxR   (    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_range$   s
    c         C   sµ   t  j g  t d ƒ D] } d d g ^ q ƒ } t  j g  t d ƒ D] } d d g ^ qA ƒ } d „  } t j | | d d d | ƒ} t  j d d g d d g g ƒ } t | | ƒ d S(	   s5   Test that bootstrap works with multiple input arrays.i
   i   i   c         S   s   t  j |  | f ƒ j d d ƒ S(   Nt   axisi    (   R   t   vstackR   (   t   xt   y(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   f2   s    R
   i   R   N(   R   R    R    R   R   t   arrayR   (   R   t   iR!   R"   R#   t
   out_actualt
   out_wanted(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_multiarg-   s    ..	!c         C   s‰   t  j j d d ƒ } d } t j | d | ƒ} | j | f k sH t ‚ t j | d | d d ƒ} | j s… t | | j d f ƒ ‚ d S(	   s&   Test axis kwarg to bootstrap function.i
   i   id   R
   R   i    i   N(   R   R   R   R   R   t   shapeR   (   R   R!   R
   t   out_defaultt   out_axis(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_axis:   s    c         C   sS   t  j j d ƒ } d } t j | d | ƒ} t j | d | ƒ} t | | ƒ d S(   s?   Test that we can get reproducible resamples by seeding the RNG.i2   i*   t   random_seedN(   R   R   R   R   R   R   (   R   t   dataR   t   boots1t   boots2(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_random_seedF   s
    c         C   s[   t  j j d ƒ } d } t j | d | d t d t  j ƒ} t  j | ƒ | k sW t ‚ d S(   s   Test smooth bootstrap.i   id   R
   t   smoothR   N(   R   R   R   R   R   t   TrueR   R   (   R   R!   R
   t
   out_smooth(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_smooth_bootstrapO   s
    c   	      C   s-  d „  } t  j t  j j d d ƒ t  j d ƒ f ƒ } d d d d d g } t  j | | ƒ t  j j d ƒ d } t  j | | ƒ t  j j d ƒ } d	 } t j | | d
 | d | ƒ} t j | | d
 | d | ƒ} | j | d f k sð t	 ‚ | j | d f k st	 ‚ | j
 ƒ  | j
 ƒ  k s)t	 ‚ d S(   s    Test bootstrap of OLS model fit.c         S   s:   t  j j t  j |  j |  ƒ ƒ } | j |  j ƒ j | ƒ S(   N(   R   t   linalgt   invt   dott   T(   t   XR"   t   XtXinv(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   ols_fitZ   s    !i2   i   i   i    i   i   i   iô  R
   R   N(   R   t   column_stackR   R   R   R8   R   R   R)   R   t   std(	   R   R<   R:   t   wt   y_noisyt
   y_lownoiseR
   t   w_boot_noisyt   w_boot_lownoise(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_olsX   s    	-&"		c         C   s®   t  j j d ƒ } t  j t d ƒ d ƒ } t  j j d d d ƒ } | | } | | } d } t j | d | ƒ} t j | d | d | ƒ} | j ƒ  | j ƒ  k sª t	 ‚ d	 S(
   s@   Test that results make sense when passing unit IDs to bootstrap.i2   i
   i   i    i   iM   R-   t   unitsN(
   R   R   R   t   repeatR    t   normalR   R   R>   R   (   R   R.   t   idst   bwerrt   data_rmR   t
   boots_origt   boots_rm(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_unitsp   s    

c           C   s<   t  j t ƒ ' t j t j d ƒ t j d ƒ ƒ Wd QXd S(   s1   Test that different length args raise ValueError.i   i
   N(   t   pytestt   raisest
   ValueErrorR   R   R   t   arange(    (    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_arglength~   s    c          C   sá   t  j j d ƒ }  t j |  d d d d ƒ} t j |  d t  j d d ƒ} t  j | | ƒ sc t ‚ t j |  d d d d ƒ} t j |  d t  j d d ƒ} t  j | | ƒ s´ t ‚ t	 j
 t ƒ  t j |  d d ƒWd QXd S(	   sA   Test that named numpy methods are the same as the numpy function.id   R   t   meanR-   i    R>   t   not_a_method_nameN(   R   R   R   R   R   RS   t   array_equalR   R>   RN   RO   t   AttributeError(   R!   t   res_at   res_b(    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   test_bootstrap_string_func„   s    (   t   numpyR   t   external.six.movesR    t   numpy.testingR   RN   t    R   R   t   fixtureR   R   R   R   R(   R,   R1   R5   RD   RM   RR   RY   (    (    (    s<   lib/python2.7/site-packages/seaborn/tests/test_algorithms.pyt   <module>   s    	
												