U
    Kvf	                     @   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d Zdd	 Zejd
 Zdd Zdd Zedkrxe  dS )ztests 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)
    Nassert_array_almost_equal)pcapcasvd)	princomp1	princomp2	princomp3datac                 C   sZ   | dd  \}}}||j  d }t|| |j d t|| |jd t||j d d S )N   r      )Zcoefr   factorsvaluesZravel)pcaresZprincompr   evalsevecsmsign r   F/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/sandbox/tests/test_pca.pycheck_pca_princomp   s
    r   c                 C   s`   | \}}}}|\}}}}	t ||d ||	 d }
t |
|	 |d t |
| |d t ||d d S )N   r   r   r   )r   	pcasvdresxreducedr   r   r   xred_svdfactors_svd	evals_svd	evecs_svdr   r   r   r   check_pca_svd   s    r   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 d } t| t t td dd d f td dd d f d dd} t| t d S )N   r   )Zdemean)r   xfr   r   r   Zmeanr   )r   r   r   r   test_pca_princomp&   s    

2
6r   c                  C   s   t t\} }}}tj|t|jd dff }tt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 )	Nr   r
      r   )Zkeepdimr         )r   r   npZc_ZonesshapedotZlinalgZpinvr   Tr   r   )r   r   r   r   Zfactors_wconstbetar   r   r   r   r   r   r   r   r   r   test_pca_svd1   s    r(   __main__)__doc__Znumpyr#   Znumpy.testingr   Zstatsmodels.sandbox.toolsr   r   Z.statsmodels.multivariate.tests.results.datamlwr   r   r   r	   r   r   Zxor   r   r(   __name__r   r   r   r   <module>   s   	

