Ë
    ¢�DjG�  ã                   óÂ  — d Z ddlmZmZ ddlmZ ddlZddlZ	ddl
mZ ddlmZ ddlmZ d„ Zd	„ Zd)d
„Zd„ Zd„ Z	 	 	 d*d„Zd+d„Z	 	 d,d„Zd-d„Z G d„ d ee«      «      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ d ee«      «      Z G d„ d e«      Z  G d!„ d"e«      Z! G d#„ d$e«      Z" G d%„ d&e«      Z# G d'„ d(e«      Z$y).z•
Spline and other smoother classes for Generalized Additive Models

Author: Luca Puggini
Author: Josef Perktold

Created on Fri Jun  5 16:32:00 2015
é    )ÚABCMetaÚabstractmethod)Úwith_metaclassN)Údmatrix)Ú_get_all_sorted_knots)Útransf_constraintsc                 ó~   — |dz
  }| j                  «       }| j                  «       }t        j                  |||«      }|S )Né   )ÚminÚmaxÚnpÚlinspace)ÚxÚdfÚn_knotsÚx_minÚx_maxÚknotss         ú`C:\Crop_Prediction\Backend\crop-ai-system\venv\Lib\site-packages\statsmodels/gam/smooth_basis.pyÚ_equally_spaced_knotsr      s8   € Ø�1‰f€GØ�E‰E‹G€EØ�E‰E‹G€EÜ�K‰K˜˜u gÓ.€EØ€Ló    c           
      ó  — t        j                  |«      }t        j                  |j                  d¬«      D �cg c]  }t        j                  | d|z  «      ‘Œ c}«      }|j	                  |j
                  d¬«      S c c}w )NÚC)Úorderéd   )r   ÚasarrayÚravelÚ
percentileÚreshapeÚshape)r   ÚprobsÚprobÚ	quantiless       r   Ú_R_compat_quantiler$       sq   € ä�J‰J�uÓ€EÜ—
‘
Ø(-¯©¸#¨Ó(>ö@Ø $ô ŸM™M¨!¨S°4©ZÕ8ò @ó A€Ià×Ñ˜UŸ[™[°ÐÓ4Ð4ùò@s   ¹ A=c                 óÌ  — 	 ddl m} t        j                  t        j
                  |t        ¬«      «      }|j                  dk(  sJ ‚|j                  «        t        |«      }t        j                  | «      } | j                  dk(  r| j                  d   dk(  r	| d d …df   } | j                  dk(  sJ ‚t        j                  | «      t        j                  |«      k  s+t        j                  | «      t        j                  |«      kD  rt        d«      ‚dt        |«      z
  }t        |«      |dz   z
  |z
  }|dv r,t        j                  | j                  d   |ft        ¬«      }|}	|d	v r,t        j                  | j                  d   |ft        ¬«      }
|
}	|d
v r,t        j                  | j                  d   |ft        ¬«      }|}	t!        |«      D ]o  }t        j"                  ||z   f«      }d|||z   <   |}|dv r || |||f«      d d …|f<   |d	v r || |||fd¬«      
d d …|f<   |d
v sŒ[ || |||fd¬«      d d …|f<   Œq |dk(  r
fS 	S # t        $ r t        d«      ‚w xY w)Nr   )Úsplevz#spline functionality requires scipy©Údtypeé   r
   zksome data points fall outside the outermost knots, and I'm not sure how to handle them. (Patches accepted!))Úallr   )r*   r)   )r*   r
   )Úderr*   )Úscipy.interpolater&   ÚImportErrorr   Ú
atleast_1dr   ÚfloatÚndimÚsortÚintr    r   r   ÚNotImplementedErrorÚlenÚemptyÚrangeÚzeros)r   r   ÚdegreeÚderivÚinclude_interceptr&   Úk_constÚn_basesÚbasisÚretÚ
der1_basisÚ
der2_basisÚiÚcoefsÚiis                  r   Ú_eval_bspline_basisrD   +   s]  € ðAÝ+ô �M‰Mœ"Ÿ*™* U´%Ô8Ó9€EØ�:‰:˜Š?ÑØ	‡J�J„LÜ�‹[€FÜ
�‰�aÓ€AØ‡v�v�‚{�q—w‘w˜q‘z Q’ØŠa�ˆd‰GˆØ�6‰6�QŠ;Ñô
 
‡v�vˆaƒy”2—6‘6˜%“=Ò ¤B§F¡F¨1£I´·±°u³Ò$=Ü!ð #Hó Ið 	Ið  ”#Ð'Ó(Ñ(€GÜ�%‹j˜F Q™JÑ'¨'Ñ1€GØ�
ÑÜ—‘˜!Ÿ'™' !™* gÐ.´eÔ<ˆØˆØ�
ÑÜ—X‘X˜qŸw™w q™z¨7Ð3¼5ÔAˆ
ØˆØ�
ÑÜ—X‘X˜qŸw™w q™z¨7Ð3¼5ÔAˆ
Øˆä�7‹^ò 
HˆÜ—‘˜' GÑ+Ð-Ó.ˆàˆˆa�'‰kÑØˆØ�JÑÙ   U¨E°6Ð$:Ó;ˆE’!�R�%‰LØ�JÑÙ % a¨%°¸Ð)?ÀQÔ GˆJ’q˜"�uÑØ�JÒÙ % a¨%°¸Ð)?ÀQÔ GˆJ’q˜"�uÒð
Hð �‚~Ø�j *Ð,Ð,àˆ
øô{ ò AÜÐ?Ó@Ð@ðAús   ‚I ÉI#c                 ó   — |dz   }||z
  }t        j                  | «      }t        j                  | «      }t        j                  dd|dz   «      dd }t	        | |«      }t        j
                  ||g|z  |f«      }	|	|||fS )Nr)   r   r
   éÿÿÿÿ)r   r   r   r   r$   Úconcatenate)
r   r   r8   r   Ún_inner_knotsÚlower_boundÚupper_boundÚknot_quantilesÚinner_knotsÚ	all_knotss
             r   Úcompute_all_knotsrN   n   s‰   € Ø�Q‰J€EØ˜‘J€MÜ—&‘&˜“)€KÜ—&‘&˜“)€KÜ—[‘[  A }°qÑ'8Ó9¸!¸BÐ?€NÜ$ Q¨Ó7€KÜ—‘ ¨kÐ :¸UÑ BØ +ð -ó .€Ià�k ;°Ð;Ð;r   c                 óR   — t        | ||«      \  }}}}t        | ||«      \  }}}|||fS )z make a spline basis for x )rN   rD   )r   r   r8   rM   Ú_r=   Ú	der_basisr@   s           r   Úmake_bsplines_basisrR   z   s=   € ô +¨1¨b°&Ó9Ñ€Iˆq�!�QÜ#6°q¸)ÀVÓ#LÑ €Eˆ9�jØ�)˜ZÐ'Ð'r   c                 ó  — |�|S | j                  «       }| j                  «       }	|dk  rt        d|›d�«      ‚t        |«      |k7  rt        d|›d�«      ‚|€|€t        d«      ‚|dz   }
|�Å||
z
  }|dk  rt        d|›d	|›d
||z
  ›�«      ‚|�/t	        |«      |k7  r”t        d|›d|›d|›dt	        |«      ›d�	«      ‚|dk(  r*t        j                  dd|dz   «      dd }t        | |«      }nD|dk(  r4t        j                  dd|dz   «      dd }|||	|z
  z  z   }|d   |d   z
  }nt        d«      ‚|�|}|€t        j                   | «      }|€t        j                  | «      }||kD  rt        d|›d|›d�«      ‚t        j                  «      }|j                  dkD  rt        d«      ‚t        j                  ||k  «      rt        d|||k     ›d|›d�«      ‚t        j                  ||kD  «      rt        d|||kD     ›d|›d�«      ‚|dk(  rKt        j                  d|
dz   «      z  }|d   |ddd…   z
  }|d   |z   }t        j                  |||f«      }nt        j                  ||g|
z  |f«      }|j                  «        |S )a7  knots for use in B-splines

    There are two main options for the knot placement

    - quantile spacing with multiplicity of boundary knots
    - equal spacing extended to boundary or exterior knots

    The first corresponds to splines as used by patsy. the second is the
    knot spacing for P-Splines.
    Nr   z#degree must be greater than 0 (not ú)zdegree must be an integer (not zmust specify either df or knotsr)   zdf=z is too small for degree=z; must be >= z with degree=z	 implies z knots, but z knots were providedÚquantiler
   rF   Úequalzincorrect option for spacingzlower_bound > upper_bound (z > zknots must be 1 dimensionalzsome knot values (z) fall below lower bound (z) fall above upper bound ()r   r   Ú
ValueErrorr2   r4   r   r   r$   r   r0   ÚanyÚarangerG   r1   )r   r   r   r8   ÚspacingrI   rJ   rM   r   r   r   rH   rK   rL   ÚgridÚ
diff_knotsÚdiffsÚlower_knotsÚupper_knotss                      r   Úget_knots_bsplinesr`   ‚   sé  € ð ÐØÐà�E‰E‹G€EØ�E‰E‹G€Eà�‚zÝÚ"ð%ó &ð 	&ä
ˆ6ƒ{�fÒÝÚ"ð%ó &ð 	&ð
 
€z�e�mÜÐ:Ó;Ð;Ø�Q‰J€EØ	€~Ø˜U™
ˆØ˜1ÒÝÚ "¢Fð !# ]Ò 2ð4ó 5ð 5ð ÐÜ�5‹z˜]Ò*Ý â$&ªÚ$1´3°uµ:ð"?ó @ð @ð ˜
Ò"äŸ[™[¨¨A¨}¸qÑ/@ÓAÀ!ÀBÐGˆNÜ,¨Q°Ó?‰KØ˜Òä—;‘;˜q ! ]°QÑ%6Ó7¸¸"Ð=ˆDØ $¨%°%©-Ñ"8Ñ8ˆKØ$ Q™¨+°a©.Ñ8‰JäÐ;Ó<Ð<ØÐØˆØÐÜ—f‘f˜Q“iˆØÐÜ—f‘f˜Q“iˆà�[Ò ÝÚ'ªð6ó 7ð 	7ä—*‘*˜[Ó)€KØ×Ñ˜!ÒÜÐ6Ó7Ð7Ü	‡v�vˆk˜KÑ'Ô(Ýà'¨°kÑ(AÓBÚ'ð)ó *ð 	*ô 
‡v�vˆk˜KÑ'Ô(Ýà'¨°kÑ(AÓBÚ'ð)ó *ð 	*ð
 �'ÒÜ—	‘	˜!˜U Q™YÓ'¨*Ñ4ˆØ! !‘n u©T¨r¨T¡{Ñ2ˆØ! "‘o¨Ñ-ˆÜ—N‘N K°¸kÐ#JÓK‰	ä—N‘N [°+Ð$>ÀÑ$FØ$/ð$1ó 2ˆ	à‡N�NÔàÐr   c                 ó  — |dz   }t        j                  | «      } t        j                  |«      |z  }t        j                  | «      }|dd…df   |z  }t        j                  | dd…df   |z   j                  «       | d   gf«      }|S )zmadd points to each subinterval defined by knots

    inserts k_points between each two consecutive knots
    r)   NrF   )r   ÚuniquerY   ÚdiffrG   r   )r   Úk_pointsÚdxiÚdxkÚdxr   s         r   Ú_get_integration_pointsrh   á   s†   € ð
 ˜!‰|€HÜ�I‰I�eÓ€EÜ
�)‰)�HÓ
 Ñ
(€CÜ
�'‰'�%‹.€CØ	ŠQ�ˆW‰˜Ñ	€BÜ
�‰˜˜s ˜s D˜yÑ)¨BÑ.×5Ñ5Ó7¸%À¹)¸ÐEÓF€AØ€Hr   c                 óæ   — 	 ddl m} | j                  }|€t        ||¬«      }n|}| j                  |||¬«      } ||dd…dd…df   |dd…ddd…f   z  |d¬«      }	|	S # t        $ r	 ddl m} Y Œgw xY w)zû
    Approximate integral of cross product of second derivative of smoother

    This uses scipy.integrate simps to compute an approximation to the
    integral of the smoother derivative cross-product at knots plus k_points
    in between knots.
    r   )Úsimpson)ÚsimpsN)rd   )r9   Úskip_ctransf)r   Úaxis)Úscipy.integraterj   r-   rk   r   rh   Ú	transform)
Úsmootherrd   Úintegration_pointsrl   r9   rj   r   r   Úd2Úcovd2s
             r   Úget_covder2rt   ï   sƒ   € ð5Ý+ð �N‰N€EØÐ!Ü# E°HÔ=‰àˆØ	×	Ñ	˜A U¸Ð	Ó	F€BÙ�B’qš!˜T�z‘N Rª¨4²¨
¡^Ñ3°q¸qÔA€EØ€Løô ò 5ç4ð5ús   ‚A ÁA0Á/A0c                 óŠ  — |rd}nd}t        | «      }t        j                  ||dz   |z
  f¬«      }t        j                  ||dz   |z
  f¬«      }t        j                  ||dz   |z
  f¬«      }t        ||dz   «      D ]A  }| |z  |dd…||z
  f<   || |dz
  z  z  |dd…||z
  f<   ||dz
  z  | |dz
  z  z  |dd…||z
  f<   ŒC |||fS )zj
    given a vector x returns poly=(1, x, x^2, ..., x^degree)
    and its first and second derivative
    r   r)   ©r    Nr
   )r4   r   r7   r6   )	r   r8   Ú	interceptÚstartÚnobsr=   rQ   r@   rA   s	            r   Úmake_poly_basisrz     só   € ñ Ø‰àˆäˆq‹6€DÜ�H‰H˜D &¨1¡*¨uÑ"4Ð5Ô6€EÜ—‘  f¨q¡j°5Ñ&8Ð9Ô:€IÜ—‘  v°¡z°EÑ'9Ð :Ô;€Jä�5˜& 1™*Ó%ò >ˆØ 1™fˆŠa��U‘ˆlÑØ"# a¨A°©E¡lÑ"2ˆ	’!�Q˜‘Y�,ÑØ#$¨¨A©¡;°°q¸1±u±Ñ#=ˆ
’1�a˜%‘i�<Ò ð>ð
 �)˜ZÐ'Ð'r   c                   ó(   — e Zd ZdZdd„Zed„ «       Zy)ÚUnivariateGamSmootherz+Base Class for single smooth component
    Nc                 ó~  — || _         || _        || _        t        |«      dc| _        | _        | j                  «       }|dk(  r|d   j                  d«      d d d …f   }|�#t        |t        «      st        |«      }|| _        nt        | d«      sd | _        |\  | _        | _        | _        | _        | j                  ��| j                  }|d   �|d   j#                  |«      | _        |d   �|d   j#                  |«      | _        |d   �|d   j#                  |«      | _        |d   �2|j$                  j#                  |d   «      j#                  |«      | _        | j                  j&                  d   | _        t+        | j(                  «      D �cg c]  }| j                  dz   t        |«      z   ‘Œ c}| _        y c c}w )Nr)   Úcenterr   Úctransfr
   é   Ú_s)r   ÚconstraintsÚvariable_namer4   ry   Úk_variablesÚ!_smooth_basis_for_single_variableÚmeanÚ
isinstanceÚstrr   r   Úhasattrr=   rQ   r@   Úcov_der2ÚdotÚTr    Ú	dim_basisr6   Ú	col_names)Úselfr   r‚   rƒ   Úbase4r   rA   s          r   Ú__init__zUnivariateGamSmoother.__init__3  s”  € ØˆŒØ&ˆÔØ*ˆÔÜ&)¨!£f¨aÐ#ˆŒ	�4Ô#à×6Ñ6Ó8ˆØ˜(Ò"Ø ™(Ÿ-™-¨Ó*¨4²¨7Ñ3ˆKàÐ"¬:°kÄ3Ô+GÜ(¨Ó5ˆGØ"ˆD�Lô ˜4 Ô+Ø#�”àEJÑBˆŒ
�D”N D¤O°T´]Ø�<‰<Ð#Ø—l‘lˆGà�Q‰xÐ#Ø" 1™XŸ\™\¨'Ó2�”
Ø�Q‰xÐ#Ø!& q¡§¡¨gÓ!6�”Ø�Q‰xÐ#Ø"'¨¡(§,¡,¨wÓ"7�”Ø�Q‰xÐ#Ø '§	¡	§¡¨e°A©hÓ 7× ;Ñ ;¸GÓ D�”àŸ™×)Ñ)¨!Ñ,ˆŒä#(¨¯©Ó#8ö:Øð ×,Ñ,¨tÑ3´c¸!³fÓ<ò :ˆ�ùò :s   Æ"F:c                  ó   — y ©N© ©r�   s    r   r…   z7UnivariateGamSmoother._smooth_basis_for_single_variableW  s   € àr   ©Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r‘   r   r…   r”   r   r   r|   r|   0  s!   „ ñó":ðH ñó ñr   r|   c                   ó,   ‡ — e Zd ZdZ	 dˆ fd„	Zd„ Zˆ xZS )ÚUnivariateGenericSmootherz$Generic single smooth component
    c                 ó`   •— || _         || _        || _        || _        t        ‰| �  ||¬«       y ©N)rƒ   )r=   rQ   r@   rŠ   Úsuperr‘   )r�   r   r=   rQ   r@   rŠ   rƒ   Ú	__class__s          €r   r‘   z"UnivariateGenericSmoother.__init___  s1   ø€ àˆŒ
Ø"ˆŒØ$ˆŒØ ˆŒä‰Ñ˜¨-ÐÕ8r   c                 ó^   — | j                   | j                  | j                  | j                  fS r“   )r=   rQ   r@   rŠ   r•   s    r   r…   z;UnivariateGenericSmoother._smooth_basis_for_single_variableh  s!   € Ø�z‰z˜4Ÿ>™>¨4¯?©?¸D¿M¹MÐIÐIr   ©r   ©r—   r˜   r™   rš   r‘   r…   Ú__classcell__©r    s   @r   rœ   rœ   \  s   ø„ ñð  #õ9öJr   rœ   c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )ÚUnivariatePolynomialSmootherz'polynomial single smooth component
    c                 ó6   •— || _         t        ‰| �	  ||¬«       y rž   )r8   rŸ   r‘   )r�   r   r8   rƒ   r    s       €r   r‘   z%UnivariatePolynomialSmoother.__init__o  s   ø€ ØˆŒÜ‰Ñ˜¨-ÐÕ8r   c                 óZ  — t        j                  | j                  | j                  f¬«      }t        j                  | j                  | j                  f¬«      }t        j                  | j                  | j                  f¬«      }t	        | j                  «      D ]j  }|dz   }| j
                  |z  |dd…|f<   || j
                  |dz
  z  z  |dd…|f<   |dkD  r#||dz
  z  | j
                  |dz
  z  z  |dd…|f<   Œbd|dd…|f<   Œl t        j                  |j                  |«      }||||fS )zv
        given a vector x returns poly=(1, x, x^2, ..., x^degree)
        and its first and second derivative
        rv   r)   Nr
   r   )r   r7   ry   r8   r6   r   r‹   rŒ   )r�   r=   rQ   r@   rA   ÚdgrŠ   s          r   r…   z>UnivariatePolynomialSmoother._smooth_basis_for_single_variables  s  € ô —‘ §	¡	¨4¯;©;Ð7Ô8ˆÜ—H‘H D§I¡I¨t¯{©{Ð#;Ô<ˆ	Ü—X‘X T§Y¡Y°·±Ð$<Ô=ˆ
Ü�t—{‘{Ó#ò 	%ˆAØ�Q‘ˆBØŸ&™& B™,ˆE’!�Q�$‰KØ  4§6¡6¨b°1©fÑ#5Ñ5ˆI’a˜�d‰OØ�AŠvØ#%¨¨a©¡=°4·6±6¸bÀ1¹fÑ3EÑ#E�
š1˜a˜4Ò à#$�
š1˜a˜4Ò ð	%ô —6‘6˜*Ÿ,™,¨
Ó3ˆà�i ¨XÐ5Ð5r   r¢   r£   r¥   s   @r   r§   r§   l  s   ø„ ñõ9ö6r   r§   c                   ó8   ‡ — e Zd ZdZ	 	 	 dˆ fd„	Zd„ Zdd„Zˆ xZS )ÚUnivariateBSplinesaW  B-Spline single smooth component

    This creates and holds the B-Spline basis function for one
    component.

    Parameters
    ----------
    x : ndarray, 1-D
        underlying explanatory variable for smooth terms.
    df : int
        number of basis functions or degrees of freedom
    degree : int
        degree of the spline
    include_intercept : bool
        If False, then the basis functions are transformed so that they
        do not include a constant. This avoids perfect collinearity if
        a constant or several components are included in the model.
    constraints : {None, str, array}
        Constraints are used to transform the basis functions to satisfy
        those constraints.
        `constraints = 'center'` applies a linear transform to remove the
        constant and center the basis functions.
    variable_name : {None, str}
        The name for the underlying explanatory variable, x, used in for
        creating the column and parameter names for the basis functions.
    covder2_kwds : {None, dict}
        options for computing the penalty matrix from the second derivative
        of the spline.
    knot_kwds : {None, list[dict]}
        option for the knot selection.
        By default knots are selected in the same way as in patsy, however the
        number of knots is independent of keeping or removing the constant.
        Interior knot selection is based on quantiles of the data and is the
        same in patsy and mgcv. Boundary points are at the limits of the data
        range.
        The available options use with `get_knots_bsplines` are

        - knots : None or array
          interior knots
        - spacing : 'quantile' or 'equal'
        - lower_bound : None or float
          location of lower boundary knots, all boundary knots are at the same
          point
        - upper_bound : None or float
          location of upper boundary knots, all boundary knots are at the same
          point
        - all_knots : None or array
          If all knots are provided, then those will be taken as given and
          all other options will be ignored.
    c                 ó’   •— || _         || _        || _        t        |f||dœ|¤Ž| _        |�|ni | _        t        ‰	| �  |||¬«       y )N)r8   r   ©r‚   rƒ   )r8   r   r:   r`   r   Úcovder2_kwdsrŸ   r‘   )
r�   r   r   r8   r:   r‚   rƒ   r¯   Ú	knot_kwdsr    s
            €r   r‘   zUnivariateBSplines.__init__¾  s_   ø€ ð ˆŒØˆŒØ!2ˆÔÜ'¨ÐM°&¸RÑMÀ9ÑMˆŒ
Ø-9Ð-E™\Ø"$ð 	Ôä‰ÑØ˜;°mð 	õ 	
r   c                 ó´   — t        | j                  | j                  | j                  | j                  ¬«      \  }}}t        | fddi| j                  ¤Ž}||||fS )N)r:   rl   T)rD   r   r   r8   r:   rt   r¯   )r�   r=   rQ   r@   rŠ   s        r   r…   z4UnivariateBSplines._smooth_basis_for_single_variableË  sc   € Ü':Ø�F‰F�D—J‘J §¡Ø"×4Ñ4ô(6Ñ$ˆˆy˜*ô
 ˜tñ 4°$ð 4Ø!%×!2Ñ!2ñ4ˆð �i ¨XÐ5Ð5r   c                 óÖ   — |€| j                   }t        || j                  | j                  || j                  ¬«      }t        | dd«      }|�|s|j                  | j                  «      }|S )aÅ  create the spline basis for new observations

        The main use of this stateful transformation is for prediction
        using the same specification of the spline basis.

        Parameters
        ----------
        x_new : ndarray
            observations of the underlying explanatory variable
        deriv : int
            which derivative of the spline basis to compute
            This is an options for internal computation.
        skip_ctransf : bool
            whether to skip the constraint transform
            This is an options for internal computation.

        Returns
        -------
        basis : ndarray
            design matrix for the spline basis for given ``x_new``
        N)r9   r:   r   )r   rD   r   r8   r:   Úgetattrr‹   r   )r�   Úx_newr9   rl   Úexogr   s         r   ro   zUnivariateBSplines.transformÖ  sf   € ð. ˆ=Ø—F‘FˆEÜ" 5¨$¯*©*°d·k±kØ).Ø59×5KÑ5KôMˆô
 ˜$ 	¨4Ó0ˆØÐ¡|Ø—8‘8˜DŸL™LÓ)ˆDØˆr   )r€   FNr   N)r   F)r—   r˜   r™   rš   r‘   r…   ro   r¤   r¥   s   @r   r¬   r¬   ‹  s$   ø„ ñ1ðd ;@Ø14Ø"õ
ò	6÷!r   r¬   c                   óP   ‡ — e Zd ZdZ	 	 d	ˆ fd„	Zd
d„Zd„ Zd„ Zdd„Zd„ Z	d„ Z
ˆ xZS )ÚUnivariateCubicSplinesziCubic Spline single smooth component

    Cubic splines as described in the wood's book in chapter 3
    c                 óª   •— d| _         || _        || _        | j                  |d¬«      x| _        }t        ||«      | _        t        ‰| �!  |||¬«       y )Nr€   T©Ú
initializer®   )	r8   r   Útransform_data_methodÚtransform_datar   r   r   rŸ   r‘   )r�   r   r   r‚   ro   rƒ   r    s         €r   r‘   zUnivariateCubicSplines.__init__   s^   ø€ ð ˆŒØˆŒØ%.ˆÔ"à×(Ñ(¨°tÐ(Ó<Ð<ˆŒ�Ü*¨1¨bÓ1ˆŒ
Ü‰ÑØ˜;°mð 	õ 	
r   c                 ó¨  — | j                   }|€|S |du r‡|dk(  r-|j                  d«      | _        |j                  d«      | _        n7t        |t        «      r|d   | _        |d   | _        d| _         nt        d«      ‚| j                  | j                  z
  | _        | j                   dk(  r|| j                  z
  | j                  z  }|S t        d«      ‚)NTÚdomainr   r)   z-transform should be None, 'domain' or a tuplezincorrect transform_data_method)	r»   r   Ú
domain_lowr   Ú
domain_uppr‡   ÚtuplerW   Údomain_diff)r�   r   rº   Útms       r   r¼   z%UnivariateCubicSplines.transform_data  sË   € Ø×'Ñ'ˆØˆ:ØˆHà˜ÑØ�XŠ~Ø"#§%¡%¨£(�”Ø"#§%¡%¨£(�•Ü˜B¤Ô&Ø"$ Q¡%�”Ø"$ Q¡%�”Ø-5�Õ*ä ð ".ó /ð /à#Ÿ™°·±Ñ@ˆDÔà×%Ñ%¨Ò1Ø�T—_‘_Ñ$¨×(8Ñ(8Ñ8ˆAØˆHäÐ>Ó?Ð?r   c                 ór  — | j                  «       d d …d d…f   }| j                  dk(  s=|d d …dd …f   j                  d«      | _        |d d …dd …fxx   | j                  z  cc<   n't	        j
                  |j                  d   «      | _        | j                  «       d d…d d…f   }| j                  dk(  sAt	        j                  dt	        j                  t	        j                  |«      d¬«      z  «      }n"t	        j                  |j                  d   «      }| j                  dk(  r|dd  }|| _        |d d |fS )NrF   Únoner)   r   )rm   zno-const)Ú
_splines_xr‚   r†   Útransf_meanr   r7   r    Ú
_splines_sÚdiagr   ÚabsÚeyer   )r�   r=   Úsr   s       r   r…   z8UnivariateCubicSplines._smooth_basis_for_single_variable%  s  € à—‘Ó!¢! S b S &Ñ)ˆà×Ñ 6Ò)Ø$¢Q¨© U™|×0Ñ0°Ó3ˆDÔØ’!�Q‘R�%‹L˜D×,Ñ,Ñ,ŒLä!Ÿx™x¨¯©°A©Ó7ˆDÔØ�O‰OÓ˜c˜r˜c 3 B 3˜hÑ'ˆØ×Ñ 6Ò)Ü—g‘g˜a¤§¡¤r§v¡v¨e£}¸1Ô =Ñ=Ó>‰Gä—f‘f˜UŸ[™[¨™^Ó,ˆGð ×Ñ˜zÒ)Ø˜a˜b�kˆGàˆŒà�d˜D !Ð#Ð#r   c                 óÌ   — |dz
  dz  dz
  |dz
  dz  dz
  z  dz  }t        j                  ||z
  «      dz
  dz  dt        j                  ||z
  «      dz
  dz  z  z
  dz   dz  }||z
  S )Ng      à?r
   gUUUUUUµ?é   gÞÝÝÝÝÝ�?g      8@)r   rÊ   )r�   r   ÚzÚp1Úp2s        r   Ú_rkzUnivariateCubicSplines._rk=  s†   € Ø�5‰y˜QÑ Ñ'¨Q°©Y¸1Ñ,<¸vÑ,EÑFÈÑJˆÜ�v‰v�a˜!‘e‹}˜uÑ$¨Ñ*Ø”r—v‘v˜a !™e“} uÑ,°Ñ2Ñ2ñ3àñàñˆð �B‰wˆr   c                 óJ  — |€| j                   }t        | j                  «      dz   }|j                  d   }t	        j
                  ||f¬«      }||d d …df<   t        |«      D ]>  \  }}t        | j                  «      D ]!  \  }}| j                  ||«      }	|	|||dz   f<   Œ# Œ@ |S )Nr
   r   rv   r)   )r   r4   r   r    r   ÚonesÚ	enumeraterÒ   )
r�   r   Ú	n_columnsry   r=   rA   ÚxiÚjÚxkjÚs_ijs
             r   rÆ   z!UnivariateCubicSplines._splines_xD  sª   € Øˆ9Ø—‘ˆAÜ˜Ÿ
™
“O aÑ'ˆ	Ø�w‰w�q‰zˆÜ—‘˜t YÐ/Ô0ˆØˆŠa�ˆd‰ä˜q“\ò 	'‰EˆAˆrÜ# D§J¡JÓ/ò '‘��3Ø—x‘x  CÓ(�Ø"&��a˜˜Q™�h’ñ'ð	'ð ˆr   c                 ó  — t        | j                  «      dz   }t        j                  ||f¬«      }t	        | j                  «      D ]?  \  }}t	        | j                  «      D ]"  \  }}| j                  ||«      ||dz   |dz   f<   Œ$ ŒA |S )Nr
   rv   )r4   r   r   r7   rÕ   rÒ   )r�   ÚqrÌ   rA   Úx1rØ   Úx2s          r   rÈ   z!UnivariateCubicSplines._splines_sR  s…   € Ü�—
‘
‹O˜aÑˆÜ�H‰H˜A˜q˜6Ô"ˆÜ˜tŸz™zÓ*ò 	3‰EˆAˆrÜ" 4§:¡:Ó.ò 3‘��2Ø"&§(¡(¨2¨rÓ"2��!�a‘%˜˜Q™�,’ñ3ð	3ð ˆr   c                 óÖ   — | j                  |d¬«      }| j                  |«      }|d d …dd …fxx   | j                  z  cc<   | j                  �|j	                  | j                  «      }|S )NFr¹   r)   )r¼   rÆ   rÇ   r   r‹   ©r�   r´   rµ   s      r   ro   z UnivariateCubicSplines.transformZ  s`   € Ø×#Ñ# E°eÐ#Ó<ˆØ�‰˜uÓ%ˆØŠQ�‘ˆU‹�t×'Ñ'Ñ'‹Ø�<‰<Ð#Ø—8‘8˜DŸL™LÓ)ˆDØˆr   )Nr¾   r   )Fr“   )r—   r˜   r™   rš   r‘   r¼   r…   rÒ   rÆ   rÈ   ro   r¤   r¥   s   @r   r·   r·   ú  s5   ø„ ñð
 ;CØ"õ
ó@ò0$ò0óòör   r·   c                   ó<   ‡ — e Zd ZdZdˆ fd„	Zd„ Zd„ Zd„ Zd„ Zˆ xZ	S )ÚUnivariateCubicCyclicSplinesa  cyclic cubic regression spline single smooth component

    This creates and holds the Cyclic CubicSpline basis function for one
    component.

    Parameters
    ----------
    x : ndarray, 1-D
        underlying explanatory variable for smooth terms.
    df : int
        number of basis functions or degrees of freedom
    degree : int
        degree of the spline
    include_intercept : bool
        If False, then the basis functions are transformed so that they
        do not include a constant. This avoids perfect collinearity if
        a constant or several components are included in the model.
    constraints : {None, str, array}
        Constraints are used to transform the basis functions to satisfy
        those constraints.
        `constraints = 'center'` applies a linear transform to remove the
        constant and center the basis functions.
    variable_name : None or str
        The name for the underlying explanatory variable, x, used in for
        creating the column and parameter names for the basis functions.
    c                 óv   •— d| _         || _        || _        t        ||«      | _        t
        ‰| �  |||¬«       y )Nr€   r®   )r8   r   r   r   r   rŸ   r‘   )r�   r   r   r‚   rƒ   r    s        €r   r‘   z%UnivariateCubicCyclicSplines.__init__~  s?   ø€ ØˆŒØˆŒØˆŒÜ*¨1¨bÓ1ˆŒ
Ü‰ÑØ˜;°mð 	õ 	
r   c                 ó6  — t        dt        | j                  «      z   dz   d| j                  i«      }|j                  | _        | j                  dz
  dz   }t        | j                  |d d d ¬«      }| j                  |«      \  }}| j                  ||«      }|d d |fS )Nz	cc(x, df=z) - 1r   r
   r)   )rH   rL   rI   rJ   )r   rˆ   r   r   Údesign_infor   Ú_get_b_and_dÚ_get_s)r�   r=   rH   rM   ÚbÚdrÌ   s          r   r…   z>UnivariateCubicCyclicSplines._smooth_basis_for_single_variable‡  s—   € Ü˜¤c¨$¯'©'£lÑ2°WÑ<¸sÀDÇFÁF¸mÓLˆØ ×,Ñ,ˆÔØŸ™ !™ a™ˆä)¨$¯&©&ÀØ6:Ø6:ÈôNˆ	ð × Ñ  Ó+‰ˆˆ1Ø�K‰K˜˜1Óˆà�d˜D !Ð#Ð#r   c                 ó   — |dd |dd z
  }|j                   dz
  }t        j                  ||f«      }t        j                  ||f«      }||dz
     |d   z   dz  |d<   ||dz
     dz  |d|dz
  f<   ||dz
     dz  ||dz
  df<   d|d   z  d	||dz
     z  z
  |d<   d	||dz
     z  |d|dz
  f<   d	||dz
     z  ||dz
  df<   t        d|«      D ]}  }||dz
     ||   z   dz  |||f<   ||dz
     dz  |||dz
  f<   ||dz
     dz  ||dz
  |f<   d||dz
     z  d	||   z  z
  |||f<   d	||dz
     z  |||dz
  f<   d	||dz
     z  ||dz
  |f<   Œ ||fS )
aÔ  Returns mapping of cyclic cubic spline values to 2nd derivatives.

        .. note:: See 'Generalized Additive Models', Simon N. Wood, 2006,
           pp 146-147

        Parameters
        ----------
        knots : ndarray
            The 1-d array knots used for cubic spline parametrization,
            must be sorted in ascending order.

        Returns
        -------
        b : ndarray
            Array for mapping cyclic cubic spline values at knots to
            second derivatives.
        d : ndarray
            Array for mapping cyclic cubic spline values at knots to
            second derivatives.

        Notes
        -----
        The penalty matrix is equal to ``s = d.T.dot(b^-1).dot(d)``
        r)   NrF   r   g      @)r   r   g      @g      ð¿g      ð?)Úsizer   r7   r6   )r�   r   ÚhÚnrè   ré   rA   s          r   ræ   z)UnivariateCubicCyclicSplines._get_b_and_d•  sÝ  € ð2 �!�"ˆI˜˜c˜r˜
Ñ"ˆØ�J‰J˜‰Nˆô
 �H‰H�a˜�VÓˆÜ�H‰H�a˜�VÓˆà�Q˜‘U‘8˜a ™d‘? bÑ(ˆˆ$‰Ø˜˜A™‘h ‘mˆˆ!ˆQ�‰Uˆ(‰Ø˜˜A™‘h ‘mˆˆ!ˆa‰%�ˆ(‰à˜˜!™‘*˜r A a¨!¡e¡H™}Ñ,ˆˆ$‰Ø˜1˜Q ™U™8‘mˆˆ!ˆQ�‰Uˆ(‰Ø˜1˜Q ™U™8‘mˆˆ!ˆa‰%�ˆ(‰ä�q˜!“ò 	(ˆAØ˜˜Q™‘x ! A¡$‘¨"Ñ,ˆAˆa�ˆd‰GØ˜A ™E™( R™-ˆAˆa��Q‘ˆh‰KØ˜A ™E™( R™-ˆAˆa�!‰e�Qˆh‰Kà˜A˜a !™e™H‘n r¨A¨a©D¡yÑ0ˆAˆa�ˆd‰GØ˜q  Q¡™x™-ˆAˆa��Q‘ˆh‰KØ˜q  Q¡™x™-ˆAˆa�!‰e�QˆhŠKð	(ð �!ˆtˆr   c                 ó�   — |j                   j                  t        j                  j	                  |«      «      j                  |«      S r“   )rŒ   r‹   r   ÚlinalgÚinv)r�   rè   ré   s      r   rç   z#UnivariateCubicCyclicSplines._get_sÊ  s-   € Ø�s‰s�w‰w”r—y‘y—}‘} QÓ'Ó(×,Ñ,¨QÓ/Ð/r   c                 ó„   — t        | j                  d|i«      }| j                  �|j                  | j                  «      }|S r–   )r   rå   r   r‹   rà   s      r   ro   z&UnivariateCubicCyclicSplines.transformÍ  s9   € Ü�t×'Ñ'¨#¨u¨Ó6ˆØ�<‰<Ð#Ø—8‘8˜DŸL™LÓ)ˆDØˆr   r–   )
r—   r˜   r™   rš   r‘   r…   ræ   rç   ro   r¤   r¥   s   @r   râ   râ   c  s"   ø„ ñõ4
ò$ò3òj0ör   râ   c                   ó.   — e Zd ZdZdd„Zed„ «       Zd„ Zy)ÚAdditiveGamSmootherz.Base class for additive smooth components
    Nc                 óL  — t        |t        j                  «      r|j                  j	                  «       }n*t        |t        j
                  «      r|j                  g}nd }t        j                  |«      }|j                  dk(  r2|j                  «       | _        t        |«      df| j                  _        n|| _        | j                  j                  \  | _        | _        t        |t         «      r|g| j                  z  | _        n|| _        |€?|�|| _        n<t'        | j                  «      D �cg c]  }dt)        |«      z   ‘Œ c}| _        n|| _        | j+                  «       | _        t        j.                  t1        d„ | j,                  D «       «      «      | _        | j2                  j                  d   | _        | j,                  D �cg c]  }|j6                  ‘Œ c}| _        g | _        | j,                  D ]'  }| j:                  j=                  |j:                  «       Œ) g | _        d}| j,                  D ]a  }t        j@                  dg| j4                  z  «      }	d|	||j4                  |z    ||j4                  z   }| j>                  jC                  |	«       Œc y c c}w c c}w )Nr)   r   c              3   ó4   K  — | ]  }|j                   –— Œ y ­wr“   )r=   )Ú.0rp   s     r   ú	<genexpr>z/AdditiveGamSmoother.__init__.<locals>.<genexpr>ú  s   è ø€ ò $?Ø#+ð %-§N¥Nñ $?ùs   ‚r   FT)"r‡   ÚpdÚ	DataFrameÚcolumnsÚtolistÚSeriesÚnamer   r   r0   Úcopyr   r4   r    ry   r„   Úboolr:   Úvariable_namesr6   rˆ   Ú_make_smoothers_listÚ	smoothersÚhstackÚlistr=   r�   rŠ   Úpenalty_matricesrŽ   ÚextendÚmaskÚarrayÚappend)
r�   r   r   r:   ÚkwargsÚ
data_namesrA   rp   Úlast_columnr  s
             r   r‘   zAdditiveGamSmoother.__init__×  s8  € ô �aœŸ™Ô&ØŸ™×)Ñ)Ó+‰JÜ˜œ2Ÿ9™9Ô%ØŸ&™&˜‰JàˆJä�J‰J�q‹Mˆà�6‰6�QŠ;Ø—V‘V“XˆDŒFÜ ›F A˜;ˆD�F‰F�LàˆDŒFà&*§f¡f§l¡lÑ#ˆŒ	�4Ô#ÜÐ'¬Ô.Ø&7Ð%8¸4×;KÑ;KÑ%KˆDÕ"à%6ˆDÔ"àÐ!ØÐ%Ø&0�Õ#ô 16°d×6FÑ6FÓ0Gö'IØ+,ð (+¬S°«V£|ò 'I�Õ#ð #1ˆDÔà×2Ñ2Ó4ˆŒÜ—Y‘Yœtñ $?Ø/3¯~©~ô$?ó  ?ó @ˆŒ
àŸ™×)Ñ)¨!Ñ,ˆŒà15·±ö!AØ%-ð "*×!2Ó!2ò !AˆÔàˆŒØŸ™ò 	6ˆHØ�N‰N×!Ñ! (×"4Ñ"4Õ5ð	6ð ˆŒ	ØˆØŸ™ò 	#ˆHÜ—8‘8˜U˜G d§n¡nÑ4Ó5ˆDØAEˆD�˜X×/Ñ/°+Ñ=Ð>Ø%¨×(:Ñ(:Ñ:ˆKØ�I‰I×Ñ˜TÕ"ñ		#ùò#'Iùò!As   Ä0JÇ
J!c                  ó   — y r“   r”   r•   s    r   r  z(AdditiveGamSmoother._make_smoothers_list  s   € àr   c                 óà   ‡ ‡— ‰j                   dk(  r!‰ j                  dk(  r‰j                  dd«      Št        j                  t        ˆ ˆfd„t        ‰ j                  «      D «       «      «      }|S )a²  create the spline basis for new observations

        The main use of this stateful transformation is for prediction
        using the same specification of the spline basis.

        Parameters
        ----------
        x_new: ndarray
            observations of the underlying explanatory variable

        Returns
        -------
        basis : ndarray
            design matrix for the spline basis for given ``x_new``.
        r)   rF   c              3   óh   •K  — | ])  }‰j                   |   j                  ‰d d …|f   «      –— Œ+ y ­wr“   )r  ro   )rö   rA   r�   r´   s     €€r   r÷   z0AdditiveGamSmoother.transform.<locals>.<genexpr>!  s5   øè ø€ ò ;Øð #Ÿn™n¨QÑ/×9Ñ9¸%ÂÀ1À¹+×Fñ ;ùs   ƒ/2)r0   r„   r   r   r  r  r6   rà   s   `` r   ro   zAdditiveGamSmoother.transform  s_   ù€ ð  �:‰:˜Š?˜t×/Ñ/°1Ò4Ø—M‘M " aÓ(ˆEÜ�y‰yœô ;Ü"'¨×(8Ñ(8Ó"9ô;ó ;ó <ˆàˆr   )NF)r—   r˜   r™   rš   r‘   r   r  ro   r”   r   r   ró   ró   Ô  s&   „ ñó2#ðh ñó ðór   ró   c                   ó(   ‡ — e Zd ZdZˆ fd„Zd„ Zˆ xZS )ÚGenericSmoothersz9generic class for additive smooth components for GAM
    c                 ó6   •— || _         t        ‰| �	  |d ¬«       y ©N)r   )r  rŸ   r‘   )r�   r   r  r    s      €r   r‘   zGenericSmoothers.__init__)  s   ø€ Ø"ˆŒÜ‰Ñ˜¨4ÐÕ0r   c                 ó   — | j                   S r“   )r  r•   s    r   r  z%GenericSmoothers._make_smoothers_list-  s   € Ø�~‰~Ðr   ©r—   r˜   r™   rš   r‘   r  r¤   r¥   s   @r   r  r  &  s   ø„ ñô1ör   r  c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )ÚPolynomialSmootherz+additive polynomial components for GAM
    c                 ó6   •— || _         t        ‰| �	  ||¬«       y r  )ÚdegreesrŸ   r‘   )r�   r   r  r   r    s       €r   r‘   zPolynomialSmoother.__init__4  s   ø€ ØˆŒÜ‰Ñ˜¨>ÐÕ:r   c                 óÒ   — g }t        | j                  «      D ]L  }t        | j                  d d …|f   | j                  |   | j
                  |   ¬«      }|j                  |«       ŒN |S )N)r8   rƒ   )r6   r„   r§   r   r  r   r	  ©r�   r  ÚvÚuv_smoothers       r   r  z'PolynomialSmoother._make_smoothers_list8  sk   € Øˆ	Ü�t×'Ñ'Ó(ò 	*ˆAÜ6Ø—‘’q˜!�t‘Ø—|‘| A‘Ø"×1Ñ1°!Ñ4ô6ˆKð ×Ñ˜[Õ)ð	*ð Ðr   r“   r  r¥   s   @r   r  r  1  s   ø„ ñõ;ör   r  c                   ó.   ‡ — e Zd ZdZ	 	 dˆ fd„	Zd„ Zˆ xZS )ÚBSplinesa9  additive smooth components using B-Splines

    This creates and holds the B-Spline basis function for several
    components.

    Parameters
    ----------
    x : array_like, 1-D or 2-D
        underlying explanatory variable for smooth terms.
        If 2-dimensional, then observations should be in rows and
        explanatory variables in columns.
    df :  {int, array_like[int]}
        number of basis functions or degrees of freedom; should be equal
        in length to the number of columns of `x`; may be an integer if
        `x` has one column or is 1-D.
    degree : {int, array_like[int]}
        degree(s) of the spline; the same length and type rules apply as
        to `df`
    include_intercept : bool
        If False, then the basis functions are transformed so that they
        do not include a constant. This avoids perfect collinearity if
        a constant or several components are included in the model.
    constraints : {None, str, array}
        Constraints are used to transform the basis functions to satisfy
        those constraints.
        `constraints = 'center'` applies a linear transform to remove the
        constant and center the basis functions.
    variable_names : {list[str], None}
        The names for the underlying explanatory variables, x used in for
        creating the column and parameter names for the basis functions.
        If ``x`` is a pandas object, then the names will be taken from it.
    knot_kwds : None or list of dict
        option for the knot selection.
        By default knots are selected in the same way as in patsy, however the
        number of knots is independent of keeping or removing the constant.
        Interior knot selection is based on quantiles of the data and is the
        same in patsy and mgcv. Boundary points are at the limits of the data
        range.
        The available options use with `get_knots_bsplines` are

        - knots : None or array
          interior knots
        - spacing : 'quantile' or 'equal'
        - lower_bound : None or float
          location of lower boundary knots, all boundary knots are at the same
          point
        - upper_bound : None or float
          location of upper boundary knots, all boundary knots are at the same
          point
        - all_knots : None or array
          If all knots are provided, then those will be taken as given and
          all other options will be ignored.


    Attributes
    ----------
    smoothers : list of univariate smooth component instances
    basis : design matrix, array of spline bases columns for all components
    penalty_matrices : list of penalty matrices, one for each smooth term
    dim_basis : number of columns in the basis
    k_variables : number of smooth components
    col_names : created names for the basis columns

    There are additional attributes about the specification of the splines
    and some attributes mainly for internal use.

    Notes
    -----
    A constant in the spline basis function can be removed in two different
    ways.
    The first is by dropping one basis column and normalizing the
    remaining columns. This is obtained by the default
    ``include_intercept=False, constraints=None``
    The second option is by using the centering transform which is a linear
    transformation of all basis functions. As a consequence of the
    transformation, the B-spline basis functions do not have locally bounded
    support anymore. This is obtained ``constraints='center'``. In this case
    ``include_intercept`` will be automatically set to True to avoid
    dropping an additional column.
    c                 ó8  •— t        |t        «      r"t        j                  |gt        ¬«      | _        n|| _        t        |t        «      r"t        j                  |gt        ¬«      | _        n|| _        || _        || _        |dk(  rd}t        ‰| �%  |||¬«       y )Nr'   r~   T)r:   r   )
r‡   r2   r   r  r  Údfsr°   r‚   rŸ   r‘   )	r�   r   r   r8   r:   r‚   r   r°   r    s	           €r   r‘   zBSplines.__init__”  s…   ø€ ä�fœcÔ"ÜŸ8™8 V H´CÔ8ˆD�Là!ˆDŒLÜ�bœ#ÔÜ—x‘x  ¬CÔ0ˆD�HàˆDŒHØ"ˆŒà&ˆÔØ˜(Ò"Ø $Ðä‰ÑØØ/Ø)ð 	õ 	
r   c           
      ó\  — g }t        | j                  «      D ]‘  }| j                  r| j                  |   ni }t        | j                  d d …|f   f| j
                  |   | j                  |   | j                  |   | j                  | j                  |   dœ|¤Ž}|j                  |«       Œ“ |S )N)r   r8   r:   r‚   rƒ   )r6   r„   r°   r¬   r   r!  r  r:   r‚   r   r	  )r�   r  r  Úkwdsr  s        r   r  zBSplines._make_smoothers_listª  s±   € Øˆ	Ü�t×'Ñ'Ó(ò 	*ˆAØ(,¯ª�4—>‘> !Ò$¸BˆDÜ,Ø—‘’q˜!�t‘ð>à—8‘8˜A‘; t§|¡|°A¡Ø"&×"8Ñ"8¸Ñ";Ø ×,Ñ,Ø"×1Ñ1°!Ñ4ñ>ð
 9=ñ>ˆKð ×Ñ˜[Õ)ð	*ð Ðr   )FNNNr  r¥   s   @r   r  r  C  s   ø„ ñOð` 9>ØBFõ
ö,r   r  c                   ó.   ‡ — e Zd ZdZ	 	 dˆ fd„	Zd„ Zˆ xZS )ÚCubicSplinesz£additive smooth components using cubic splines as in Wood 2006.

    Note, these splines do NOT use the same spline basis as
    ``Cubic Regression Splines``.
    c                 óT   •— || _         || _        || _        t        ‰| �  |||¬«       y )N)r‚   r   )r!  r‚   ro   rŸ   r‘   )r�   r   r   r‚   ro   r   r    s         €r   r‘   zCubicSplines.__init__¿  s2   ø€ àˆŒØ&ˆÔØ"ˆŒÜ‰ÑØ˜;°~ð 	õ 	
r   c           	      óþ   — g }t        | j                  «      D ]b  }t        | j                  d d …|f   | j                  |   | j
                  | j                  | j                  |   ¬«      }|j                  |«       Œd |S )N)r   r‚   ro   rƒ   )	r6   r„   r·   r   r!  r‚   ro   r   r	  r  s       r   r  z!CubicSplines._make_smoothers_listÈ  s{   € Øˆ	Ü�t×'Ñ'Ó(ò 	*ˆAÜ0Ø ŸF™F¢1 a 4™L¨T¯X©X°a©[Ø(,×(8Ñ(8Ø&*§n¡nØ*.×*=Ñ*=¸aÑ*@ô	BˆKð
 ×Ñ˜[Õ)ð	*ð Ðr   )r~   r¾   Nr  r¥   s   @r   r%  r%  ¹  s   ø„ ñð
 ?GØ $õ
ö
r   r%  c                   ó*   ‡ — e Zd ZdZdˆ fd„	Zd„ Zˆ xZS )ÚCyclicCubicSplinesa,  additive smooth components using cyclic cubic regression splines

    This spline basis is the same as in patsy.

    Parameters
    ----------
    x : array_like, 1-D or 2-D
        underlying explanatory variable for smooth terms.
        If 2-dimensional, then observations should be in rows and
        explanatory variables in columns.
    df :  int
        numer of basis functions or degrees of freedom
    constraints : {None, str, array}
        Constraints are used to transform the basis functions to satisfy
        those constraints.
    variable_names : {list[str], None}
        The names for the underlying explanatory variables, x used in for
        creating the column and parameter names for the basis functions.
        If ``x`` is a pandas object, then the names will be taken from it.
    c                 óD   •— || _         || _        t        ‰| �  ||¬«       y r  )r!  r‚   rŸ   r‘   )r�   r   r   r‚   r   r    s        €r   r‘   zCyclicCubicSplines.__init__ê  s$   ø€ ØˆŒà&ˆÔÜ‰Ñ˜¨>ÐÕ:r   c                 óè   — g }t        | j                  «      D ]W  }t        | j                  d d …|f   | j                  |   | j
                  | j                  |   ¬«      }|j                  |«       ŒY |S )N)r   r‚   rƒ   )r6   r„   râ   r   r!  r‚   r   r	  r  s       r   r  z'CyclicCubicSplines._make_smoothers_listð  ss   € Øˆ	Ü�t×'Ñ'Ó(ò 	*ˆAÜ6Ø—‘’q˜!�t‘Ø—8‘8˜A‘;¨D×,<Ñ,<Ø"×1Ñ1°!Ñ4ô6ˆKð ×Ñ˜[Õ)ð	*ð Ðr   )NNr  r¥   s   @r   r)  r)  Õ  s   ø„ ñõ(;ö	r   r)  )r*   T)NNNr€   rU   NNN)r€   )r€   NFr
   )T)%rš   Úabcr   r   Ústatsmodels.compat.pythonr   Únumpyr   Úpandasrø   Úpatsyr   Úpatsy.mgcv_cubic_splinesr   Ústatsmodels.tools.linalgr   r   r$   rD   rN   rR   r`   rh   rt   rz   r|   rœ   r§   r¬   r·   râ   ró   r  r  r  r%  r)  r”   r   r   ú<module>r3     s  ðñ÷ (Ý 4ã Û Ý Ý :å 7ò
ò5ó@òF	<ò(ð <=Ø7;Ø37ó\ó~ð :>Ø*+óó2(ôP)™N¨7Ó3ô )ôXJÐ 5ô Jô 6Ð#8ô 6ô>lÐ.ô lô^fÐ2ô fôRnÐ#8ô nôbO™.¨Ó1ô OôdÐ*ô ôÐ,ô ô$sÐ"ô sôlÐ&ô ô8$Ð,õ $r   