ó
áp7]c           @   sÚ   d  Z  d d l Z d „  Z d „  Z d „  Z d „  Z i d d 6d	 d
 6Z d e f d „  ƒ  YZ	 i d d 6d d
 6Z d e	 f d „  ƒ  YZ
 d e d <d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d S(   s|   Examples of non-linear functions for non-parametric regression

Created on Sat Jan 05 20:21:22 2013

Author: Josef Perktold
iÿÿÿÿNc         C   s   |  d t  j d |  d ƒ S(   s(   Fan and Gijbels example function 1

    i   iðÿÿÿ(   t   npt   exp(   t   x(    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyt   fg1   s    c         C   s!   |  d t  j d |  d d ƒ S(   s:   Eubank similar to Fan and Gijbels example function 1

    g      à?iÎÿÿÿi   (   R    R   (   R   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyt   fg1eu   s    c         C   s*   t  j d |  ƒ d t  j d |  d ƒ S(   s(   Fan and Gijbels example function 2

    i   iðÿÿÿ(   R    t   sinR   (   R   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyt   fg2   s    c         C   s)   t  j |  d ƒ |  d |  d |  d S(   s&   made up example with sin, square

    i   g       @g      ð?i   (   R    R   (   R   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyt   func1   s    su   Base Class for Univariate non-linear example

    Does not work on it's own.
    needs additional at least self.func
t   descriptiont    t   reft   _UnivariateFunctionc           B   s2   e  Z d  Z d d d d d „ Z e d d „ Z RS(   s’  %(description)s

    Parameters
    ----------
    nobs : int
        number of observations to simulate
    x : None or 1d array
        If x is given then it is used for the exogenous variable instead of
        creating a random sample
    distr_x : None or distribution instance
        Only used if x is None. The rvs method is used to create a random
        sample of the exogenous (explanatory) variable.
    distr_noise : None or distribution instance
        The rvs method is used to create a random sample of the errors.

    Attributes
    ----------
    x : ndarray, 1-D
        exogenous or explanatory variable. x is sorted.
    y : ndarray, 1-D
        endogenous or response variable
    y_true : ndarray, 1-D
        expected values of endogenous or response variable, i.e. values of y
        without noise
    func : callable
        underlying function (defined by subclass)

    %(ref)s
    iÈ   c         C   sû   | d  k r^ | d  k r? t j j d d d |  j d | ƒ } n | j d | ƒ } | j ƒ  n  | |  _ | d  k rš t j j d d d |  j d | ƒ } n | j d | ƒ } t	 |  d ƒ rÔ | |  j
 |  j ƒ 9} n  |  j | ƒ |  _ } | | |  _ d  S(   Nt   loci    t   scalet   sizet	   het_scale(   t   NoneR    t   randomt   normalt   s_xt   rvst   sortR   t   s_noiset   hasattrR   t   funct   y_truet   y(   t   selft   nobsR   t   distr_xt   distr_noiset   noiseR   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyt   __init__P   s    '	'c      	   C   sÀ   | d k r? d d l j } | j ƒ  } | j d d d ƒ } n  | rg | j |  j |  j d d d ƒn  t j	 |  j j
 ƒ  |  j j ƒ  d ƒ } | j | |  j | ƒ d d	 d
 d d d ƒ| j S(   s  plot the mean function and optionally the scatter of the sample

        Parameters
        ----------
        scatter: bool
            If true, then add scatterpoints of sample to plot.
        ax : None or matplotlib axis instance
            If None, then a matplotlib.pyplot figure is created, otherwise
            the given axis, ax, is used.

        Returns
        -------
        fig : matplotlib figure
            This is either the created figure instance or the one associated
            with ax if ax is given.

        iÿÿÿÿNi   t   ot   alphag      à?id   t   lwi   t   colort   bt   labels   dgp mean(   R   t   matplotlib.pyplott   pyplott   figuret   add_subplott   plotR   R   R    t   linspacet   mint   maxR   (   R   t   scattert   axt   pltt   figt   xx(    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR+   h   s    "'+N(   t   __name__t
   __module__t   __doc__R   R    t   TrueR+   (    (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR   /   s   s=   Fan and Gijbels example function 1

linear trend plus a hump
sÈ   
References
----------
Fan, Jianqing, and Irene Gijbels. 1992. "Variable Bandwidth and Local
Linear Regression Smoothers."
The Annals of Statistics 20 (4) (December): 2008-2036. doi:10.2307/2242378.

t   UnivariateFanGijbels1c           B   s*   e  Z e j e Z d  d d d d „ Z RS(   iÈ   c      	   C   sM   d |  _  d |  _ t |  _ t |  j |  ƒ j d | d | d | d | ƒ d  S(   Ng      ð?gffffffæ?R   R   R   R   (   R   R   R   R   t   supert	   __class__R    (   R   R   R   R   R   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR    ™   s    			!N(   R4   R5   R   R6   t   docR   R    (    (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR8   •   s   s4   Fan and Gijbels example function 2

sin plus a hump
t   UnivariateFanGijbels2c           B   s*   e  Z e j e Z d  d d d d „ Z RS(   iÈ   c      	   C   sM   d |  _  d |  _ t |  _ t |  j |  ƒ j d | d | d | d | ƒ d  S(   Ng      ð?g      à?R   R   R   R   (   R   R   R   R   R9   R:   R    (   R   R   R   R   R   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR    ª   s    			!N(   R4   R5   R   R6   R;   R   R    (    (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR<   §   s   t   UnivariateFanGijbels1EUc           B   s#   e  Z d  Z d d d d d „ Z RS(   s   

    Eubank p.179f
    i2   c      	   C   sl   | d  k r( d d l m } | j } n  d |  _ t |  _ t |  j |  ƒ j	 d | d | d | d | ƒ d  S(   Niÿÿÿÿ(   t   statsg333333Ã?R   R   R   R   (
   R   t   scipyR>   t   uniformR   R   R   R9   R:   R    (   R   R   R   R   R   R>   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR    ¸   s    		!N(   R4   R5   R6   R   R    (    (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR=   ²   s   t   UnivariateFunc1c           B   s,   e  Z d  Z d d d d d „ Z d „  Z RS(   s0   

    made up, with sin and quadratic trend
    iÈ   c      	   C   s‹   | d  k r= | d  k r= d d l m } | j d d ƒ } n | j d } d |  _ t |  _ t t	 |  ƒ j
 d | d | d	 | d
 | ƒ d  S(   Niÿÿÿÿ(   R>   iþÿÿÿi   i    g       @R   R   R   R   (   R   R?   R>   R@   t   shapeR   R   R   R9   RA   R    (   R   R   R   R   R   R>   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR    È   s    		c         C   s   t  j t  j d | ƒ ƒ S(   Ni   (   R    t   sqrtt   abs(   R   R   (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyR   Ô   s    N(   R4   R5   R6   R   R    R   (    (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyRA   Â   s   (   R6   t   numpyR    R   R   R   R   R;   t   objectR   R8   R<   R=   RA   (    (    (    sM   lib/python2.7/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyt   <module>   s"   				
W	

