§
    M/Ph3  ã                   óÒ   — d Z ddlZd„ Zd„ Zd„ Zd„ Zddd	œZ G d
„ d¦  «        Zddd	œZ G d„ de¦  «        Z	ded<    G d„ de¦  «        Z
 G d„ de¦  «        Z G d„ de¦  «        ZdS )z|Examples of non-linear functions for non-parametric regression

Created on Sat Jan 05 20:21:22 2013

Author: Josef Perktold
é    Nc                 óB   — | dt          j        d| dz  z  ¦  «        z  z   S )z(Fan and Gijbels example function 1

    é   éðÿÿÿ©ÚnpÚexp©Úxs    ún/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/sandbox/nonparametric/dgp_examples.pyÚfg1r      s&   € ð ˆq•2”6˜#  1¡™*Ñ%Ô%Ñ%Ñ%Ð%ó    c                 óH   — | dt          j        d| dz
  dz  z  ¦  «        z  z   S )z:Eubank similar to Fan and Gijbels example function 1

    ç      à?iÎÿÿÿr   r   r	   s    r   Úfg1eur      s+   € ð ˆs•R”V˜C 1 s¡7¨Q¡,Ñ.Ñ/Ô/Ñ/Ñ/Ð/r   c                 ól   — t          j        d| z  ¦  «        dt          j        d| dz  z  ¦  «        z  z   S )z(Fan and Gijbels example function 2

    r   r   )r   Úsinr   r	   s    r   Úfg2r      s2   € õ Œ6!a‘%‰=Œ=˜1rœv c¨A¨q©D¡jÑ1Ô1Ñ1Ñ1Ð1r   c                 óT   — t          j        | dz  ¦  «        | z  d| z  z   d| dz  z  z
  S )z&made up example with sin, square

    é   ç       @ç      ð?r   )r   r   r	   s    r   Úfunc1r      s1   € õ Œ6!a‘%‰=Œ=˜1Ñ˜r A™vÑ%¨¨Q°©T©	Ñ1Ð1r   zuBase Class for Univariate non-linear example

    Does not work on it's own.
    needs additional at least self.func
Ú )ÚdescriptionÚrefc                   ó"   — e Zd ZdZdd„Zdd„ZdS )	Ú_UnivariateFunctiona’  %(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
    éÈ   Nc                 óæ  — |€T|€(t           j                             d| j        |¬¦  «        }n|                     |¬¦  «        }|                     ¦   «          || _        |€(t           j                             d| j        |¬¦  «        }n|                     |¬¦  «        }t          | d¦  «        r||  	                    | j        ¦  «        z  }|  
                    |¦  «        x| _        }||z   | _        d S )Nr   )ÚlocÚscaleÚsize)r"   Ú	het_scale)r   ÚrandomÚnormalÚs_xÚrvsÚsortr
   Ús_noiseÚhasattrr#   ÚfuncÚy_trueÚy)ÚselfÚnobsr
   Údistr_xÚdistr_noiseÚnoiser,   s          r   Ú__init__z_UnivariateFunction.__init__O   sÝ   € àˆ9ØˆÝ”I×$Ò$¨°$´(ÀÐ$ÑFÔFà—K’K TKÑ*Ô*ØFŠF‰HŒHˆHàˆŒàÐÝ”I×$Ò$¨°$´,ÀTÐ$ÑJÔJˆEˆEà—O’O¨OÑ.Ô.ˆEå4˜Ñ%Ô%ð 	,ØT—^’^ D¤FÑ+Ô+Ñ+ˆEð  $Ÿyšy¨™|œ|Ð+ˆŒfØ˜%‘ˆŒˆˆr   Tc                 ó¢  — |€1ddl m} |                     ¦   «         }|                     ddd¦  «        }|r#|                     | j        | j        dd¬¦  «         t          j        | j         	                    ¦   «         | j         
                    ¦   «         d¦  «        }|                     ||                      |¦  «        dd	d
¬¦  «         |j        S )a	  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
        -------
        Figure
            This is either the created figure instance or the one associated
            with ax if ax is given.

        Nr   é   Úor   )Úalphaéd   r   Úbzdgp mean)ÚlwÚcolorÚlabel)Úmatplotlib.pyplotÚpyplotÚfigureÚadd_subplotÚplotr
   r-   r   ÚlinspaceÚminÚmaxr+   )r.   ÚscatterÚaxÚpltÚfigÚxxs         r   rA   z_UnivariateFunction.plotg   s¸   € ð$ ˆ:Ø+Ð+Ð+Ð+Ð+Ð+Ø—*’*‘,”,ˆCØ—’  A qÑ)Ô)ˆBàð 	4ØGŠGD”F˜DœF C¨sˆGÑ3Ô3Ð3åŒ[˜œŸš™œ t¤v§z¢z¡|¤|°SÑ9Ô9ˆØ
ŠD—I’I˜b‘M”M a¨s¸*ˆÑEÔEÐEØŒyÐr   ©r   NNN)TN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r3   rA   © r   r   r   r   .   sC   € € € € € ð€Gð< ð  ð  ð  ð0ð ð ð ð ð r   r   z=Fan and Gijbels example function 1

linear trend plus a hump
zÈ
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.

c                   ó4   ‡ — e Zd Zej        ez  Zdˆ fd„	Zˆ xZS )ÚUnivariateFanGijbels1r   Nc                 ó”   •— d| _         d| _        t          | _        t	          | j        | ¦  «                             ||||¬¦  «         d S )Nr   gffffffæ?©r/   r
   r0   r1   )r&   r)   r   r+   ÚsuperÚ	__class__r3   ©r.   r/   r
   r0   r1   rU   s        €r   r3   zUnivariateFanGijbels1.__init__˜   óZ   ø€ ØˆŒØˆŒÝˆŒ	ÝˆdŒn˜dÑ#Ô#×,Ò,°$¸!Ø5<Ø9Dð 	-ñ 	Fô 	Fð 	Fð 	Fð 	Fr   rJ   ©rK   rL   rM   r   rN   Údocr3   Ú__classcell__©rU   s   @r   rQ   rQ   ”   sT   ø€ € € € € Ø!Ô)¨CÑ/€GðFð Fð Fð Fð Fð Fð Fð Fð Fð Fr   rQ   z4Fan and Gijbels example function 2

sin plus a hump
r   c                   ó4   ‡ — e Zd Zej        ez  Zdˆ fd„	Zˆ xZS )ÚUnivariateFanGijbels2r   Nc                 ó”   •— d| _         d| _        t          | _        t	          | j        | ¦  «                             ||||¬¦  «         d S )Nr   r   rS   )r&   r)   r   r+   rT   rU   r3   rV   s        €r   r3   zUnivariateFanGijbels2.__init__©   rW   r   rJ   rX   r[   s   @r   r]   r]   ¦   sT   ø€ € € € € Ø!Ô)¨CÑ/€GðFð Fð Fð Fð Fð Fð Fð Fð Fð Fr   r]   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚUnivariateFanGijbels1EUz

    Eubank p.179f
    é2   Nc                 ó¤   •— |€ddl m} |j        }d| _        t          | _        t          | j        | ¦  «                             ||||¬¦  «         d S )Nr   ©Ústatsg333333Ã?rS   )	Úscipyrd   Úuniformr)   r   r+   rT   rU   r3   ©r.   r/   r
   r0   r1   rd   rU   s         €r   r3   z UnivariateFanGijbels1EU.__init__·   sq   ø€ Øˆ?Ø#Ð#Ð#Ð#Ð#Ð#Ø”mˆGØˆŒÝˆŒ	ÝˆdŒn˜dÑ#Ô#×,Ò,°$¸!Ø5<Ø9Dð 	-ñ 	Fô 	Fð 	Fð 	Fð 	Fr   )ra   NNN)rK   rL   rM   rN   r3   rZ   r[   s   @r   r`   r`   ±   sQ   ø€ € € € € ðð ð
Fð Fð Fð Fð Fð Fð Fð Fð Fð Fr   r`   c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )ÚUnivariateFunc1z0

    made up, with sin and quadratic trend
    r   Nc                 óÔ   •— |€|€ddl m} |                     dd¦  «        }n|j        d         }d| _        t
          | _        t          ¦   «                              ||||¬¦  «         d S )Nr   rc   éþÿÿÿé   r   rS   )	re   rd   rf   Úshaper)   r   r+   rT   r3   rg   s         €r   r3   zUnivariateFunc1.__init__Ç   s†   ø€ Øˆ9˜˜Ø#Ð#Ð#Ð#Ð#Ð#Ø—m’m B¨Ñ*Ô*ˆGˆGà”7˜1”:ˆDØˆŒÝˆŒ	Ý‰Œ×Ò˜d aØ5<Ø9Dð 	ñ 	Fô 	Fð 	Fð 	Fð 	Fr   c                 óT   — t          j        t          j        d|z   ¦  «        ¦  «        S )Né   )r   ÚsqrtÚabs)r.   r
   s     r   r#   zUnivariateFunc1.het_scaleÓ   s   € ÝŒw•r”v˜a ™c‘{”{Ñ#Ô#Ð#r   rJ   )rK   rL   rM   rN   r3   r#   rZ   r[   s   @r   ri   ri   Á   s\   ø€ € € € € ðð ð

Fð 
Fð 
Fð 
Fð 
Fð 
Fð$ð $ð $ð $ð $ð $ð $r   ri   )rN   Únumpyr   r   r   r   r   rY   r   rQ   r]   r`   ri   rO   r   r   ú<module>rs      s“  ððð ð Ð Ð Ð ð&ð &ð &ð0ð 0ð 0ð2ð 2ð 2ð2ð 2ð 2ðð
 
ðð €ðUð Uð Uð Uð Uñ Uô Uð Uðpð
ðð €ð
Fð 
Fð 
Fð 
Fð 
FÐ/ñ 
Fô 
Fð 
Fðð €MÑ ð	Fð 	Fð 	Fð 	Fð 	FÐ/ñ 	Fô 	Fð 	FðFð Fð Fð Fð FÐ1ñ Fô Fð Fð $ð $ð $ð $ð $Ð)ñ $ô $ð $ð $ð $r   