U
    Kvfî  ã                   @   sÀ   d Z ddlZddlmZmZ ddlmZ ddlm	Z	m
Z
 G dd„ dƒZG dd	„ d	ƒZG d
d„ deeƒZG dd„ deeƒZG dd„ deeƒZedkr¼eƒ Ze ¡  e ¡  ej eƒ Ze ¡  dS )zL
Created on Fri Nov 04 10:51:39 2011

Author: Josef Perktold
License: BSD-3
é    N)Úassert_almost_equalÚassert_equal)Ú	smoothers)ÚOLSÚWLSc                   @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚCheckSmootherc                 C   sL   t | j | j¡| jjdd t | j | jd d… ¡| jjd d… dd d S )Né   ©Údecimalé
   )r   Úres_psZpredictÚxÚres2Zfittedvalues©Úself© r   úZ/tmp/pip-unpacked-wheel-2v6byqio/statsmodels/sandbox/nonparametric/tests/test_smoothers.pyÚtest_predict   s     ÿ ÿzCheckSmoother.test_predictc                 C   s   t | jj ¡ | jjdd d S )Né   r	   )r   r   ZcoefZravelr   Úparamsr   r   r   r   Ú	test_coef   s     ÿzCheckSmoother.test_coefc                 C   sH   t | j ¡ | jjd ƒ t | j ¡ | jjd ƒ t | j ¡ | jjƒ d S )Né   )r   r   Zdf_modelr   Zdf_fitZdf_residr   r   r   r   Útest_df   s    zCheckSmoother.test_dfN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   r   r      s   r   c                   @   s   e Zd Zedd„ ƒZdS )ÚBasePolySmootherc           
      C   s€   d}d}d}d\}}t  |||¡ | _}|d d …d f t  |d ¡  | _}| d¡}t j d¡ ||t j |¡   | _	}	d S )Né   g      à?éd   )éÿÿÿÿé   r   i¯ )
ÚnpZlinspacer   ZarangeÚexogÚsumÚrandomÚseedZrandnÚy)
ÚclsÚorderZsigma_noiseÚnobsZlbZubr   r"   Zy_truer&   r   r   r   Úsetup_class'   s    $
zBasePolySmoother.setup_classN)r   r   r   Úclassmethodr*   r   r   r   r   r   %   s   r   c                       s    e Zd Ze‡ fdd„ƒZ‡  ZS )ÚTestPolySmoother1c                    sd   t t| ƒ ¡  | j| j| j  }}}t d|¡}| |¡ || _	t
||d d …d d…f ƒ ¡ | _d S )Nr    r   )Úsuperr,   r*   r&   r   r"   r   ÚPolySmootherÚfitr   r   r   ©r'   r&   r   r"   Úpmod©Ú	__class__r   r   r*   7   s    
zTestPolySmoother1.setup_class©r   r   r   r+   r*   Ú__classcell__r   r   r2   r   r,   5   s   r,   c                       s    e Zd Ze‡ fdd„ƒZ‡  ZS )ÚTestPolySmoother2c                    sd   t t| ƒ ¡  | j| j| j  }}}t d|¡}| |¡ || _	t
||d d …d d…f ƒ ¡ | _d S )Nr   é   )r-   r6   r*   r&   r   r"   r   r.   Zsmoothr   r   r/   r   r0   r2   r   r   r*   F   s    
zTestPolySmoother2.setup_classr4   r   r   r2   r   r6   D   s   r6   c                       s    e Zd Ze‡ fdd„ƒZ‡  ZS )ÚTestPolySmoother3c                    s¢   t t| ƒ ¡  | j| j| j  }}}|jd }t |¡}d|d |d …< d|| d d …< t	 
d|¡}|j||d || _t||d d …d d…f |d ¡ | _d S )Nr   gš™™™™™¹?r   r    é   )Úweights)r-   r8   r*   r&   r   r"   Úshaper!   Zonesr   r.   r/   r   r   r   )r'   r&   r   r"   r)   r:   r1   r2   r   r   r*   V   s    

zTestPolySmoother3.setup_classr4   r   r   r2   r   r8   T   s   r8   Ú__main__)Ú__doc__Znumpyr!   Znumpy.testingr   r   Z!statsmodels.sandbox.nonparametricr   Z#statsmodels.regression.linear_modelr   r   r   r   r,   r6   r8   r   Út1r   r   r   Út3r   r   r   r   Ú<module>   s    