ó
áp7]c           @   s¥   d  Z  d d l Z d d l m Z d d l m Z m Z d d l m	 Z	 m
 Z
 m Z m Z d „  Z d „  Z e j d Z d	 „  Z d
 „  Z e d k r¡ e ƒ  n  d S(   só   tests for pca and arma to ar and ma representation

compared with matlab princomp, and garchar, garchma

TODO:
* convert to generators with yield to have individual tests
* incomplete: test relationship of pca-evecs and pinv (adding constant)
iÿÿÿÿN(   t   assert_array_almost_equal(   t   pcat   pcasvd(   t	   princomp1t	   princomp2t	   princomp3t   datac         C   so   |  d \ } } } | | j  d } t | | | j  d ƒ t | | | j d ƒ t | | j j ƒ  d ƒ d  S(   Ni   i    i   (   t   coefR    t   factorst   valuest   ravel(   t   pcarest   princompR   t   evalst   evecst   msign(    (    sA   lib/python2.7/site-packages/statsmodels/sandbox/tests/test_pca.pyt   check_pca_princomp   s
    c         C   s~   |  \ } } } } | \ } } } }	 t  | | d ƒ | |	 d }
 t  |
 |	 | d ƒ t  |
 | | d ƒ t  | | d ƒ d  S(   Ni   i    i   (   R    (   R   t	   pcasvdrest   xreducedR   R   R   t   xred_svdt   factors_svdt	   evals_svdt	   evecs_svdR   (    (    sA   lib/python2.7/site-packages/statsmodels/sandbox/tests/test_pca.pyt   check_pca_svd   s    g     @@c          C   sö   t  t ƒ }  t |  t ƒ t  t d  d … d  d  … f ƒ }  t |  t ƒ t  t d  d … d  d  … f t d  d … d  d  … f j d ƒ ƒ }  t |  t ƒ t  t d  d … d  d  … f t d  d … d  d  … f j d ƒ d d ƒ}  t |  t ƒ d  S(   Ni   i    t   demean(   R   t   xfR   R   R   t   meanR   (   R   (    (    sA   lib/python2.7/site-packages/statsmodels/sandbox/tests/test_pca.pyt   test_pca_princomp&   s    "EKc          C   s1  t  t ƒ \ }  } } } t j | t j | j d d f ƒ f } t j t j j | ƒ t ƒ } t	 | j
 d  d  … d  d … f | d ƒ t t d d ƒ\ } } } }	 t	 | | d ƒ | |	 d }
 t	 |
 |	 | d ƒ t	 |
 | | d ƒ t	 | |  d ƒ t  t d d ƒ} t t d d ƒ} t | | ƒ d  S(	   Ni    i   i   i   t   keepdimi   i   i   (   R   R   t   npt   c_t   onest   shapet   dott   linalgt   pinvR    t   TR   R   (   R   R   R   R   t   factors_wconstt   betaR   R   R   R   R   R   R   (    (    sA   lib/python2.7/site-packages/statsmodels/sandbox/tests/test_pca.pyt   test_pca_svd1   s    ))t   __main__(   t   __doc__t   numpyR   t   numpy.testingR    t   statsmodels.sandbox.toolsR   R   t.   statsmodels.multivariate.tests.results.datamlwR   R   R   R   R   R   t   xoR   R   R'   t   __name__(    (    (    sA   lib/python2.7/site-packages/statsmodels/sandbox/tests/test_pca.pyt   <module>   s   "		
		